Merge branch 'task/EXC-328' into 'master'

Task/exc 328

See merge request CIEFWorldwideSdnBhd/shipping-portal!54
This commit is contained in:
omair saleh
2021-09-14 03:45:35 +00:00
8 changed files with 194 additions and 28 deletions
@@ -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;
}
}
}
@@ -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;
}
}
}
@@ -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;
}
}
}
@@ -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;
}
}
}
@@ -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;
}
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace App\Console\Commands;
use App\Models\State;
use App\Http\Helpers\General;
use Illuminate\Console\Command;
use App\Classes\Jobs\FetchContainersStatusUpdateFromVTPortalJob;
use App\Classes\Jobs\FetchDeliveryListFromVTPortalJob;
use App\Classes\Jobs\FetchLoadedContainersFromVTPortalJob;
use App\Classes\Jobs\FetchPackingListFromVTPortalJob;
use App\Classes\Jobs\FetchWarehouseReceiveListFromVTPortalJob;
class CurlVTCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:curlVTCommand';
// php artisan queue:work
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
FetchWarehouseReceiveListFromVTPortalJob::withChain([
new FetchLoadedContainersFromVTPortalJob,
new FetchPackingListFromVTPortalJob,
new FetchContainersStatusUpdateFromVTPortalJob,
new FetchDeliveryListFromVTPortalJob
])->dispatch();
}
}
+9 -22
View File
@@ -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');
}
/**
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AlterTablePackages extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('packages', function (Blueprint $table) {
$table->text('description')->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}