mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
New columns at job_results table to track url, job_command_name and job_command + new JobResourceNotFoundException
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Exceptions;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
|
||||
final class JobResourceNotFoundException extends ServiceApiException {
|
||||
public function __construct(?string $message = null) {
|
||||
parent::__construct($message ?? 'Unable to find the requested resource', HttpStatus::RESOURCE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Exceptions\JobResourceNotFoundException;
|
||||
|
||||
abstract class AbstractControllerLogic
|
||||
{
|
||||
@@ -67,7 +68,19 @@ abstract class AbstractControllerLogic
|
||||
return $response;
|
||||
|
||||
} catch (ErrorException|GeneralExceptions $exception){
|
||||
log::error($exception);
|
||||
if ($exception instanceof JobResourceNotFoundException) {
|
||||
Log::error(sprintf(
|
||||
"Uncaught exception '%s' with message '%s' in %s:%d",
|
||||
get_class($exception),
|
||||
$exception->getMessage(),
|
||||
$exception->getTrace()[0]['file'],
|
||||
$exception->getTrace()[0]['line']
|
||||
));
|
||||
}
|
||||
else{
|
||||
log::error($exception);
|
||||
}
|
||||
|
||||
return (new ApiResponseObject($this->getNotificationTitle().' failed', $exception->getMessage(),
|
||||
$exception->getCode() ? $exception->getCode() : HttpStatus::SERVER_ERROR))->handler();
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@ namespace App\Classes\General\Eloquent;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use App\Classes\Exceptions\JobResourceNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Psy\Exception\ErrorException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
abstract class AbstractFetchRecord extends AbstractGetRecord
|
||||
{
|
||||
@@ -29,7 +31,13 @@ abstract class AbstractFetchRecord extends AbstractGetRecord
|
||||
*/
|
||||
public function getResults(Builder $query, array $param = []): Model {
|
||||
if(!$query->exists()){
|
||||
throw new ResourceNotFoundException('Unable to find any record based on the criteria provided');
|
||||
$table = $query->getModel()->getTable();
|
||||
if($table ==='job_results'){
|
||||
throw new JobResourceNotFoundException('Unable to find any job based on the criteria provided');
|
||||
}
|
||||
else{
|
||||
throw new ResourceNotFoundException('Unable to find any record based on the criteria provided');
|
||||
}
|
||||
}
|
||||
|
||||
return $query->first();
|
||||
|
||||
@@ -32,6 +32,15 @@ class ListBookings implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$rawPayload = $this->job->payload();
|
||||
if(isset($rawPayload['data']['commandName'])){
|
||||
$this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']);
|
||||
}
|
||||
|
||||
if(isset($rawPayload['data']['command'])){
|
||||
$this->listGenericJobObject->setJobCommand($rawPayload['data']['command']);
|
||||
}
|
||||
|
||||
$result = (App()->make(ListBookingJobProcessor::class))->execute($this->listGenericJobObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,16 @@ class ListDocuments implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$result = (App()->make(ListDocumentJobProcessor::class))->execute($this->listGenericJobObject);
|
||||
$rawPayload = $this->job->payload();
|
||||
if(isset($rawPayload['data']['commandName'])){
|
||||
$this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']);
|
||||
}
|
||||
|
||||
// Log::error(json_encode($result));
|
||||
if(isset($rawPayload['data']['command'])){
|
||||
$this->listGenericJobObject->setJobCommand($rawPayload['data']['command']);
|
||||
}
|
||||
|
||||
$result = (App()->make(ListDocumentJobProcessor::class))->execute($this->listGenericJobObject);
|
||||
|
||||
//cief todo: Insert into DB: job id, query result, timestamp
|
||||
// Store the result in the job_results table
|
||||
|
||||
@@ -32,6 +32,15 @@ class ListTransactions implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$rawPayload = $this->job->payload();
|
||||
if(isset($rawPayload['data']['commandName'])){
|
||||
$this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']);
|
||||
}
|
||||
|
||||
if(isset($rawPayload['data']['command'])){
|
||||
$this->listGenericJobObject->setJobCommand($rawPayload['data']['command']);
|
||||
}
|
||||
|
||||
$result = (App()->make(ListTransactionJobProcessor::class))->execute($this->listGenericJobObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class ListBookingJobLogic extends AbstractControllerLogic
|
||||
];
|
||||
|
||||
$listGenericJobObject = new ListGenericJobObject(
|
||||
"Proof of Concept",
|
||||
$request->fullUrl(),
|
||||
$request->all(),
|
||||
$jobId,
|
||||
$userInfo
|
||||
|
||||
@@ -39,16 +39,15 @@ class ListBookingJobProcessor
|
||||
public function execute(ListGenericJobObject $listGenericJobObject) {
|
||||
|
||||
$query = $this->listsBookings->execute($this->listsBookings->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]);
|
||||
Log::error('ListBookingJobProcessor: '. json_encode($listGenericJobObject->getuserInfo()));
|
||||
Log::error('ListBookingJobProcessor: '. json_encode(gettype($query)));
|
||||
|
||||
//cief todo: remove comments
|
||||
// $result = $this->collectionResponse(BookingResource::collection($query)->userInfo($listGenericJobObject->getuserInfo()));
|
||||
$result = $this->collectionResponse(BookingResource::customResourceCollection($query, $listGenericJobObject->getuserInfo()));
|
||||
|
||||
// $result = new JobBookingCollectionResponse($query, $listGenericJobObject->getuserInfo());
|
||||
// $result = $this->collectionResponse(new BookingResourceCollection(BookingResource::collection($query), $listGenericJobObject->getuserInfo()));
|
||||
|
||||
$create = $this->createsJobResult->execute($listGenericJobObject->getJobId(), json_encode($result));
|
||||
$create = $this->createsJobResult->execute($listGenericJobObject, json_encode($result));
|
||||
|
||||
return $create;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class ListDocumentJobLogic extends AbstractControllerLogic
|
||||
|
||||
|
||||
$listGenericJobObject = new ListGenericJobObject(
|
||||
"Proof of Concept",
|
||||
$request->fullUrl(),
|
||||
$request->all(),
|
||||
$jobId,
|
||||
$userInfo
|
||||
@@ -52,6 +52,7 @@ class ListDocumentJobLogic extends AbstractControllerLogic
|
||||
|
||||
ListDocuments::dispatch($listGenericJobObject);
|
||||
|
||||
//cief todo: remove comments
|
||||
// // Create your job instance with delay, so we can back here within delay and take control in our hands.
|
||||
// $job = new ListDocuments($listGenericJobObject);
|
||||
// $job->delay(now()->addSeconds(5));
|
||||
|
||||
@@ -40,8 +40,8 @@ class ListDocumentJobProcessor
|
||||
public function execute(ListGenericJobObject $listGenericJobObject) {
|
||||
|
||||
$query = $this->listsDocuments->execute($this->listsDocuments->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]);
|
||||
Log::error('ListDocumentJobProcessor: '. json_encode($listGenericJobObject->getuserInfo()));
|
||||
|
||||
//cief todo: remove comments
|
||||
//attempt 1
|
||||
// $result = $this->collectionResponse(DocumentResource::collection($query, $listGenericJobObject->getuserInfo()));
|
||||
|
||||
@@ -50,7 +50,7 @@ class ListDocumentJobProcessor
|
||||
$result = $this->collectionResponse(DocumentResource::customResourceCollection($query, $listGenericJobObject->getuserInfo()));
|
||||
// $result = $this->collectionResponse(new DocumentResourceCollection(DocumentResource::collection($query), $listGenericJobObject->getuserInfo()));
|
||||
|
||||
$create = $this->createsJobResult->execute($listGenericJobObject->getJobId(), json_encode($result));
|
||||
$create = $this->createsJobResult->execute($listGenericJobObject, json_encode($result));
|
||||
|
||||
return $create;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,12 @@ class ListGenericJobObject implements DataTransferObject
|
||||
/** @var object */
|
||||
private $userInfo;
|
||||
|
||||
/** @var string */
|
||||
private $jobCommandName;
|
||||
|
||||
/** @var string */
|
||||
private $jobCommand;
|
||||
|
||||
public function __construct(string $name, array $payload, string $jobId, object $userInfo = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
@@ -59,9 +65,35 @@ class ListGenericJobObject implements DataTransferObject
|
||||
return $this->userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJobCommandName(): string
|
||||
{
|
||||
return $this->jobCommandName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJobCommand(): string
|
||||
{
|
||||
return $this->jobCommand;
|
||||
}
|
||||
|
||||
// public function setJobId(int $jobId)
|
||||
// {
|
||||
// $this->jobId = $jobId;
|
||||
// }
|
||||
|
||||
public function setJobCommandName(string $jobCommandName)
|
||||
{
|
||||
$this->jobCommandName = $jobCommandName;
|
||||
}
|
||||
|
||||
public function setJobCommand(string $jobCommand)
|
||||
{
|
||||
$this->jobCommand = $jobCommand;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Classes\Modules\Jobs\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\JobResult;
|
||||
use App\Classes\Modules\Generic\DataTransferObjects\ListGenericJobObject;
|
||||
|
||||
class CreatesJobResult extends AbstractUpdateRecord
|
||||
{
|
||||
@@ -13,11 +14,14 @@ class CreatesJobResult extends AbstractUpdateRecord
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(string $job_id, string $result)
|
||||
public function execute(ListGenericJobObject $listGenericJobObject, string $result)
|
||||
{
|
||||
$model = new JobResult();
|
||||
$model->job_id = $job_id;
|
||||
$model->job_id = $listGenericJobObject->getJobId();
|
||||
$model->result = $result;
|
||||
$model->url = $listGenericJobObject->getName();
|
||||
$model->job_command_name = $listGenericJobObject->getJobCommandName();
|
||||
$model->job_command = $listGenericJobObject->getJobCommand();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
|
||||
@@ -229,26 +229,6 @@ class CreatePerfexCRMInvoiceProcessor
|
||||
);
|
||||
|
||||
$result = $this->createsPerfexCRMInvoice->execute($invoicePerfexCRMObject);
|
||||
|
||||
//cief todo: When invoices need to be regenerated, need to ensure payment do not get double created
|
||||
|
||||
// if(!is_null($result))
|
||||
// {
|
||||
// if($result->payload['id']){
|
||||
// $invoicePaymentPerfexCRMObject = new InvoicePaymentPerfexCRMObject(
|
||||
// $result->payload['id'],
|
||||
// $total,
|
||||
// $date,
|
||||
// 1,
|
||||
// "",
|
||||
// ""
|
||||
// );
|
||||
// $this->createsPerfexCRMInvoicePayment->execute($invoicePaymentPerfexCRMObject);
|
||||
// }
|
||||
// }
|
||||
//else: logs will record the following:
|
||||
//"status":false,"error":{"number":"The Invoice number is already in use"},"message":"<p>The Invoice number is already in use<\/p>"}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ class UpdatePerfexCRMProcessor
|
||||
*/
|
||||
public function execute(UpdatePerfexCRMObject $updatePerfexCRMObject) {
|
||||
$projectId = "";
|
||||
|
||||
|
||||
// Customer has to exist first before Project can appear under it
|
||||
// Check with Perfex CRM, if this user (email) was previously a lead, should automatically now become a customer
|
||||
$crmCompany = $updatePerfexCRMObject->getCompanyName();
|
||||
@@ -214,11 +214,6 @@ class UpdatePerfexCRMProcessor
|
||||
else{
|
||||
$result = $this->createsPerfexCRMTask->execute($tasks[$count]['name'], $tasks[$count]['description'], '', $milestoneId, $projectId, $tasks[$count]['reference'], $tasks[$count]['on_task_completion'], $tasks[$count]['department'], $taskStatus, $tasks[$count]['priority'], $tasks[$count]['duedate']);
|
||||
}
|
||||
|
||||
//cief todo: to evaluate if this is still needed
|
||||
// if(is_null($result)){
|
||||
// break; //Breaking the rest of the tasks in array assuming that they are all created as a batch previously
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class ListTransactionsJobLogic extends AbstractControllerLogic
|
||||
$jobId = uniqid();
|
||||
|
||||
$listGenericJobObject = new ListGenericJobObject(
|
||||
"Proof of Concept",
|
||||
$request->fullUrl(),
|
||||
$request->all(),
|
||||
$jobId
|
||||
);
|
||||
|
||||
@@ -42,7 +42,7 @@ class ListTransactionJobProcessor
|
||||
|
||||
$result = $this->collectionResponse(TransactionResource::collection($query));
|
||||
|
||||
$create = $this->createsJobResult->execute($listGenericJobObject->getJobId(), json_encode($result));
|
||||
$create = $this->createsJobResult->execute($listGenericJobObject, json_encode($result));
|
||||
|
||||
return $create;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddNewColumnToJobResultsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('job_results', function (Blueprint $table) {
|
||||
$table->string('url')->after('result')->nullable();
|
||||
$table->string('job_command_name')->after('url')->nullable();
|
||||
$table->longText('job_command')->after('job_command_name')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('job_results', function (Blueprint $table) {
|
||||
$table->dropColumn('url');
|
||||
$table->dropColumn('job_command_name');
|
||||
$table->dropColumn('job_command');
|
||||
});
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -165,7 +165,7 @@
|
||||
}
|
||||
},
|
||||
created(){
|
||||
this.submit(route('api.company.list') + '?filters=' + JSON.stringify({'business_type': 3, 'status_in': [1, 2, 0]}), 'get', 'pendingOrdersSection', false, false)
|
||||
this.submit(route('api.company.list') + '?filters=' + JSON.stringify({'business_type': 3, 'status_in': [1, 2, 0]}), 'get', 'pendingOrdersSection', false, false); //cief todo: Uncaught (in promise) null
|
||||
},
|
||||
methods: {
|
||||
successHandler(response){
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
},
|
||||
created(){
|
||||
this.setDecoratorDefault();
|
||||
this.$store.dispatch('updateListQueue', {'name': this.section, 'page': 1, 'filters': this.filters});
|
||||
this.$store.dispatch('updateListQueue', {'name': this.section, 'page': 1, 'filters': this.filters}); //cief todo: Uncaught (in promise) null
|
||||
},
|
||||
computed: {
|
||||
pendingList () {
|
||||
@@ -101,11 +101,13 @@
|
||||
this.isLoading = true;
|
||||
this.submitJob(url);
|
||||
},
|
||||
updateFilters(filters){
|
||||
this.filters = filters;
|
||||
this.setDecoratorDefault();
|
||||
this.submit(this.endpoint + '?page=1&filters=' + JSON.stringify(this.filters), 'get', this.section, false, false)
|
||||
},
|
||||
//cief todo: remove?
|
||||
// updateFilters(filters){
|
||||
// this.filters = filters;
|
||||
// this.setDecoratorDefault();
|
||||
// console.log('updateFilters');
|
||||
// this.submit(this.endpoint + '?page=1&filters=' + JSON.stringify(this.filters), 'get', this.section, false, false); //cief todo: Uncaught (in promise) null
|
||||
// },
|
||||
successHandler(response){
|
||||
let result = JSON.parse(response.payload.data.result);
|
||||
result.meta = {
|
||||
@@ -173,7 +175,7 @@
|
||||
fetchJobResult(jobId) {
|
||||
try {
|
||||
let anotherEndpoint = route('api.job.fetch', jobId);
|
||||
this.submit(anotherEndpoint, 'get', this.section, false, false);
|
||||
this.submit(anotherEndpoint, 'get', this.section, false, false); //cief todo: Uncaught (in promise) null
|
||||
} catch (error) {
|
||||
console.error('Error fetchJobResult', error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user