From 7151caa9b8c7364df80a76643c78fe206a00b002 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 11 Feb 2024 16:11:42 +0800 Subject: [PATCH] Proof of concept - Vue Polling a workaround for AWS API Gateway limitation --- app/Classes/Jobs/ListBookingsJob.php | 2 + app/Classes/Jobs/ListDocumentsJob.php | 2 + app/Classes/Jobs/ListTransactionsJob.php | 2 + .../Processors/FetchesJobResultProcessor.php | 10 +- .../Processors/UpdateJobResultProcessor.php | 4 +- .../AdminPaymentsBillingSectionComponent.vue | 26 ++-- ...PaymentsBillingSectionPollingComponent.vue | 136 ++++++++++++++++++ .../SupplierPendingOrdersSectionComponent.vue | 8 +- .../general/elements/ListPollingComponent.vue | 57 ++++---- .../views/pages/billings_experiment.blade.php | 9 ++ routes/job.php | 1 + routes/web.php | 12 +- 12 files changed, 219 insertions(+), 50 deletions(-) create mode 100644 resources/assets/vue/components/bookings/sections/AdminPaymentsBillingSectionPollingComponent.vue create mode 100644 resources/views/pages/billings_experiment.blade.php diff --git a/app/Classes/Jobs/ListBookingsJob.php b/app/Classes/Jobs/ListBookingsJob.php index 41f976a6..b021b71d 100644 --- a/app/Classes/Jobs/ListBookingsJob.php +++ b/app/Classes/Jobs/ListBookingsJob.php @@ -16,6 +16,8 @@ class ListBookingsJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + public $timeout = 900; + /** @var ListGenericJobObject */ private $listGenericJobObject; diff --git a/app/Classes/Jobs/ListDocumentsJob.php b/app/Classes/Jobs/ListDocumentsJob.php index bbadc169..6e93062b 100644 --- a/app/Classes/Jobs/ListDocumentsJob.php +++ b/app/Classes/Jobs/ListDocumentsJob.php @@ -16,6 +16,8 @@ class ListDocumentsJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + public $timeout = 900; + /** @var ListGenericJobObject */ private $listGenericJobObject; diff --git a/app/Classes/Jobs/ListTransactionsJob.php b/app/Classes/Jobs/ListTransactionsJob.php index 6b8913a2..a2b28656 100644 --- a/app/Classes/Jobs/ListTransactionsJob.php +++ b/app/Classes/Jobs/ListTransactionsJob.php @@ -16,6 +16,8 @@ class ListTransactionsJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + public $timeout = 900; + /** @var ListGenericJobObject */ private $listGenericJobObject; diff --git a/app/Classes/Modules/Jobs/Processors/FetchesJobResultProcessor.php b/app/Classes/Modules/Jobs/Processors/FetchesJobResultProcessor.php index e19456e7..89783fe8 100644 --- a/app/Classes/Modules/Jobs/Processors/FetchesJobResultProcessor.php +++ b/app/Classes/Modules/Jobs/Processors/FetchesJobResultProcessor.php @@ -2,6 +2,7 @@ namespace App\Classes\Modules\Jobs\Processors; +use App\Classes\Exceptions\JobResourceNotFoundException; use App\Classes\Modules\Jobs\Services\FetchesJobResult; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; @@ -32,12 +33,13 @@ class FetchesJobResultProcessor public function execute(Request $request){ $res1 = $this->fetchesJobResult->execute(['job_id' => $request->route('job_id')]); + if($request->route('is_last')){ + $res2 = $this->fetchesJobResult->execute(['request_signature' => $res1->request_signature, 'result_not_null' => true, 'order_by_id_desc' => true]); + return $res2; + } if(!$res1->result){ - Log::info('Job id: '.$request->route('job_id')); - $res2 = $this->fetchesJobResult->execute(['request_signature' => $res1->request_signature, 'result_not_null' => true, 'order_by_id_desc' => true]); - Log::info('Job id: '.$res2->id." , request_signature: ".$res2->request_signature); - return $res2; + throw new JobResourceNotFoundException('Unable to find any job based on the criteria provided'); } return $res1; diff --git a/app/Classes/Modules/Jobs/Processors/UpdateJobResultProcessor.php b/app/Classes/Modules/Jobs/Processors/UpdateJobResultProcessor.php index fff83bb0..0106417d 100644 --- a/app/Classes/Modules/Jobs/Processors/UpdateJobResultProcessor.php +++ b/app/Classes/Modules/Jobs/Processors/UpdateJobResultProcessor.php @@ -44,9 +44,9 @@ class UpdateJobResultProcessor try{ $jobResultExisting = $this->fetchesJobResult->execute(['request_signature' => $jobResultCurrent->request_signature, 'result_not_null' => true, 'order_by_id_desc' => true]); $resultSignatureExisting = $jobResultExisting->result_signature; - if($resultSignatureExisting != $resultSignatureCurrent){ + //if($resultSignatureExisting != $resultSignatureCurrent){ $this->updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $listGenericJobObject->getJobCommandName(), $listGenericJobObject->getJobCommand()); - } + //} } catch (JobResourceNotFoundException $exception){ $this->updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $listGenericJobObject->getJobCommandName(), $listGenericJobObject->getJobCommand()); } diff --git a/resources/assets/vue/components/bookings/sections/AdminPaymentsBillingSectionComponent.vue b/resources/assets/vue/components/bookings/sections/AdminPaymentsBillingSectionComponent.vue index 03244ff4..966ccbbc 100644 --- a/resources/assets/vue/components/bookings/sections/AdminPaymentsBillingSectionComponent.vue +++ b/resources/assets/vue/components/bookings/sections/AdminPaymentsBillingSectionComponent.vue @@ -90,34 +90,34 @@
- + - -
-
- + +
+
+ - -
-
- + +
+
+ - +
- + - -
+
+
diff --git a/resources/assets/vue/components/bookings/sections/AdminPaymentsBillingSectionPollingComponent.vue b/resources/assets/vue/components/bookings/sections/AdminPaymentsBillingSectionPollingComponent.vue new file mode 100644 index 00000000..47d14857 --- /dev/null +++ b/resources/assets/vue/components/bookings/sections/AdminPaymentsBillingSectionPollingComponent.vue @@ -0,0 +1,136 @@ + + diff --git a/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue b/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue index e6b66dcf..d2b69080 100644 --- a/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue +++ b/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue @@ -118,16 +118,16 @@
- - + +
diff --git a/resources/assets/vue/components/general/elements/ListPollingComponent.vue b/resources/assets/vue/components/general/elements/ListPollingComponent.vue index 98e2a44b..fcd3b8b8 100644 --- a/resources/assets/vue/components/general/elements/ListPollingComponent.vue +++ b/resources/assets/vue/components/general/elements/ListPollingComponent.vue @@ -50,6 +50,7 @@ diff --git a/resources/views/pages/billings_experiment.blade.php b/resources/views/pages/billings_experiment.blade.php new file mode 100644 index 00000000..d1caee2d --- /dev/null +++ b/resources/views/pages/billings_experiment.blade.php @@ -0,0 +1,9 @@ +@extends('layouts.base_portal') +@section('inner_content') +
+
+ + +
+
+@endsection diff --git a/routes/job.php b/routes/job.php index f32d142e..028e9468 100644 --- a/routes/job.php +++ b/routes/job.php @@ -4,4 +4,5 @@ use Illuminate\Support\Facades\Route; Route::group(['prefix' => 'job', 'as' => 'job.', 'namespace' => 'Jobs'], function () { Route::get('/fetch/{job_id}', 'FetchJobResultController@fetch')->name('fetch'); + Route::get('/fetch/{job_id}/{is_last}', 'FetchJobResultController@fetch')->name('fetch.last.attempt'); }); diff --git a/routes/web.php b/routes/web.php index ead4b3d2..4e9afd11 100644 --- a/routes/web.php +++ b/routes/web.php @@ -92,6 +92,12 @@ Route::get('/billings', function () { return view('pages.billings'); })->name('billings'); +/* Vue Polling Experiment - Starts */ +Route::get('/billings-experiment', function () { + return view('pages.billings_experiment'); +})->name('billings.experiment'); +/* Vue Polling Experiment - Ends */ + Route::get('/currency_orders', function () { return view('pages.currency_orders'); })->name('currency_orders'); @@ -813,13 +819,13 @@ Route::get('/invoice/{marking}/{started_at}/{ended_at}/fix', function($marking, ->withTrashed() ->orderBy('created_at', 'asc') ->first(); - + // get the first bill_no $firstBillNo = $firstInvoice->bill_no; if (strpos($firstBillNo, '-deleted') !== false) { $firstBillNo = substr($firstBillNo, 0, strpos($firstBillNo, '-deleted')); } - + // update currentInvoice bill_no to '-deleted-' $currentInvoice = $booking->transactions()->where('type', TransactionType::INVOICE)->first(); $currentInvoice->bill_no = $currentInvoice->bill_no ."-deleted-" . Str::random(10); @@ -842,4 +848,4 @@ Route::get('/invoice/{marking}/{started_at}/{ended_at}/fix', function($marking, } } ); -})->name('invoice.fix.byCustomerMarking'); \ No newline at end of file +})->name('invoice.fix.byCustomerMarking');