mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-22 22:14:08 +00:00
72 lines
2.5 KiB
PHP
72 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\V2;
|
|
|
|
use App\Classes\Jobs\UpdatePerfexCRMPrelude;
|
|
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
|
use Illuminate\Console\Command;
|
|
use App\Models\DelayedJob;
|
|
use App\Models\PackingList;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class ProcessDelayedJobsV2Command extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'process-delayed-jobs-command';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Process and dispatch delayed jobs';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$jobs = DelayedJob::orderBy('execute_at')
|
|
->limit(150)
|
|
->get();
|
|
|
|
$count = 0;
|
|
foreach ($jobs as $index => $delayedJob) {
|
|
$jobClass = $delayedJob->job_class;
|
|
if($jobClass === UpdatePerfexCRMPrelude::class){
|
|
$params = json_decode($delayedJob->parameters, true);
|
|
|
|
Log::info('ProcessDelayedJobsV2Command packingList : ' . json_encode($params['packingList']));
|
|
Log::info('ProcessDelayedJobsV2Command packingList id : ' . json_encode($params['packingList']['id']));
|
|
Log::info('ProcessDelayedJobsV2Command transaction : ' . json_encode($params['transaction']));
|
|
Log::info('ProcessDelayedJobsV2Command updatePerfexCRMObject : ' . json_encode($params['updatePerfexCRMObject']));
|
|
Log::info('ProcessDelayedJobsV2Command shouldCreateInvoice : ' . json_encode($params['shouldCreateInvoice']));
|
|
|
|
$updatePerfexCRMObject = UpdatePerfexCRMObject::fromJson(json_encode($params['updatePerfexCRMObject']));
|
|
$packingList = PackingList::where('id', $params['packingList']['id'])->first();
|
|
|
|
$singleDelayedJob = new $jobClass(
|
|
$packingList,
|
|
$params['transaction'],
|
|
$updatePerfexCRMObject,
|
|
$params['shouldCreateInvoice']
|
|
);
|
|
|
|
$delayInSeconds = intdiv($index, 2) * 10 ;
|
|
dispatch($singleDelayedJob)->delay(now()->addSeconds($delayInSeconds));
|
|
$delayedJob->delete();
|
|
$count++;
|
|
}
|
|
|
|
}
|
|
Log::info('ProcessDelayedJobsV2Command Total delayed jobs processed and dispatched: ' . $count);
|
|
}
|
|
}
|