diff --git a/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php index 0a0c0158..1a2ab2f1 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchContainersStatusUpdateFromVTPortalProcessor.php @@ -68,6 +68,10 @@ class FetchContainersStatusUpdateFromVTPortalProcessor */ public function execute(){ + $time_start = microtime(true); + $task_name = "FetchContainersStatusUpdateFromVTPortalProcessor"; + self::timer($task_name, $time_start); + try { $containers = Container::where('status', '=', ApprovalStatus::PENDING_VERIFICATION)->get(); @@ -147,9 +151,22 @@ class FetchContainersStatusUpdateFromVTPortalProcessor Log::error($exception); } + $time_end = microtime(true); + self::timer($task_name, $time_start, $time_end); + return []; } - + private static function timer($task="", $time_start=0, $time_end=0){ + if ($time_end > 0) { + $execution_time = ($time_end - $time_start)/60; + $execution_time = round($execution_time,2); + $date = date("Y-m-d H:i a", $time_end); + echo "$task ends at $date (took $execution_time minutes)". PHP_EOL; + } else { + $date = date("Y-m-d H:i a", $time_start); + echo "$task starts at $date". PHP_EOL; + } + } } diff --git a/app/Classes/Modules/PackingLists/Processors/FetchDeliveryListFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchDeliveryListFromVTPortalProcessor.php index fbab0c5b..98aadfbd 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchDeliveryListFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchDeliveryListFromVTPortalProcessor.php @@ -54,6 +54,10 @@ class FetchDeliveryListFromVTPortalProcessor */ public function execute(){ + $time_start = microtime(true); + $task_name = "FetchDeliveryListFromVTPortalProcessor"; + self::timer($task_name, $time_start); + try { $packingLists = PackingList::where('type', '=', PackingListType::SHIPPING_PACKING_LIST)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::SUSPENDED])->get(); @@ -95,9 +99,22 @@ class FetchDeliveryListFromVTPortalProcessor Log::error($exception); } + $time_end = microtime(true); + self::timer($task_name, $time_start, $time_end); + return []; } - + private static function timer($task="", $time_start=0, $time_end=0){ + if ($time_end > 0) { + $execution_time = ($time_end - $time_start)/60; + $execution_time = round($execution_time,2); + $date = date("Y-m-d H:i a", $time_end); + echo "$task ends at $date (took $execution_time minutes)". PHP_EOL; + } else { + $date = date("Y-m-d H:i a", $time_start); + echo "$task starts at $date". PHP_EOL; + } + } } diff --git a/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php index 4069a40d..e3313f48 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchLoadedContainersFromVTPortalProcessor.php @@ -124,7 +124,12 @@ class FetchLoadedContainersFromVTPortalProcessor */ public function execute(?Carbon $start = null, ?Carbon $end = null){ + $time_start = microtime(true); + $task_name = "FetchLoadedContainersFromVTPortalProcessor"; + self::timer($task_name, $time_start); + DB::beginTransaction(); + try { $start = $start ? $start : Carbon::now()->subMonth(); @@ -217,17 +222,29 @@ class FetchLoadedContainersFromVTPortalProcessor } } - } } catch (\Exception $exception){ Log::error($exception); } - DB::commit(); + + $time_end = microtime(true); + self::timer($task_name, $time_start, $time_end); + return []; } - + private static function timer($task="", $time_start=0, $time_end=0){ + if ($time_end > 0) { + $execution_time = ($time_end - $time_start)/60; + $execution_time = round($execution_time,2); + $date = date("Y-m-d H:i a", $time_end); + echo "$task ends at $date (took $execution_time minutes)". PHP_EOL; + } else { + $date = date("Y-m-d H:i a", $time_start); + echo "$task starts at $date". PHP_EOL; + } + } } diff --git a/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php index ecc9c9f0..d9b61644 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchPackingListFromVTPortalProcessor.php @@ -46,6 +46,10 @@ class FetchPackingListFromVTPortalProcessor */ public function execute(){ + $time_start = microtime(true); + $task_name = "FetchPackingListFromVTPortalProcessor"; + self::timer($task_name, $time_start); + $packingLists = PackingList::where('type', '=', PackingListType::SHIPPING_PACKING_LIST)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::SUSPENDED])->whereDoesntHave('containers', function($query){ $query->where('status', '=', ApprovalStatus::COMPLETED); })->get(); @@ -79,9 +83,25 @@ class FetchPackingListFromVTPortalProcessor } + $time_end = microtime(true); + self::timer($task_name, $time_start, $time_end); + return []; } + private static function timer($task="", $time_start=0, $time_end=0){ + if ($time_end > 0) { + $execution_time = ($time_end - $time_start)/60; + $execution_time = round($execution_time,2); + $date = date("Y-m-d H:i a", $time_end); + echo "$task ends at $date (took $execution_time minutes)". PHP_EOL; + } else { + $date = date("Y-m-d H:i a", $time_start); + echo "$task starts at $date". PHP_EOL; + } + } } + + diff --git a/app/Classes/Modules/PackingLists/Processors/FetchWarehouseReceiveListFromVTPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchWarehouseReceiveListFromVTPortalProcessor.php index b9043479..6756dd2e 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchWarehouseReceiveListFromVTPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchWarehouseReceiveListFromVTPortalProcessor.php @@ -112,6 +112,10 @@ class FetchWarehouseReceiveListFromVTPortalProcessor */ public function execute(?Carbon $start = null, ?Carbon $end = null){ + $time_start = microtime(true); + $task_name = "FetchWarehouseReceiveListFromVTPortalProcessor"; + self::timer($task_name, $time_start); + DB::beginTransaction(); try { @@ -132,6 +136,9 @@ class FetchWarehouseReceiveListFromVTPortalProcessor $response = $this->fetchesDataFRomVTPortal->getResponseBody($warehouseListRequest); + $time_elapsed_secs = microtime(true) - $timer; + echo 'Time '.$timer. PHP_EOL; + foreach ($response->Rows as $parcel){ $marking = explode('/', explode('CIEF/', $parcel[5])[1]); @@ -233,9 +240,23 @@ class FetchWarehouseReceiveListFromVTPortalProcessor } DB::commit(); + + $time_end = microtime(true); + self::timer($task_name, $time_start, $time_end); + return []; } - + private static function timer($task="", $time_start=0, $time_end=0){ + if ($time_end > 0) { + $execution_time = ($time_end - $time_start)/60; + $execution_time = round($execution_time,2); + $date = date("Y-m-d H:i a", $time_end); + echo "$task ends at $date (took $execution_time minutes)". PHP_EOL; + } else { + $date = date("Y-m-d H:i a", $time_start); + echo "$task starts at $date". PHP_EOL; + } + } } diff --git a/app/Console/Commands/CurlVTCommand.php b/app/Console/Commands/CurlVTCommand.php new file mode 100644 index 00000000..e779cd5c --- /dev/null +++ b/app/Console/Commands/CurlVTCommand.php @@ -0,0 +1,57 @@ +dispatch(); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 623233c2..2e082565 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -17,9 +17,7 @@ class Kernel extends ConsoleKernel * * @var array */ - protected $commands = [ - // - ]; + protected $commands = []; /** * Define the application's command schedule. @@ -29,26 +27,15 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { + $schedule->command('command:curlVTCommand') + ->dailyAt('15:00') + ->withoutOverlapping() + ->appendOutputTo (storage_path().'/logs/curlvt.log'); - $schedule->call(function(){ - return FetchWarehouseReceiveListFromVTPortalJob::withChain([ - new FetchLoadedContainersFromVTPortalJob, - new FetchPackingListFromVTPortalJob, - new FetchContainersStatusUpdateFromVTPortalJob, - new FetchDeliveryListFromVTPortalJob - ])->dispatch(); - })->dailyAt('15:00'); - - $schedule->call(function(){ - return FetchWarehouseReceiveListFromVTPortalJob::withChain([ - new FetchLoadedContainersFromVTPortalJob, - new FetchPackingListFromVTPortalJob, - new FetchContainersStatusUpdateFromVTPortalJob, - new FetchDeliveryListFromVTPortalJob - ])->dispatch(); - })->dailyAt('21:00'); - - + $schedule->command('command:curlVTCommand') + ->dailyAt('21:00') + ->withoutOverlapping() + ->appendOutputTo (storage_path().'/logs/curlvt.log'); } /** diff --git a/database/migrations/2021_09_12_124121_alter_table_packages.php b/database/migrations/2021_09_12_124121_alter_table_packages.php new file mode 100644 index 00000000..f0c4c311 --- /dev/null +++ b/database/migrations/2021_09_12_124121_alter_table_packages.php @@ -0,0 +1,30 @@ +text('description')->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}