Files
shipping-portal/app/Console/Commands/V2/ProcessDelayedJobsV2Command.php
T

71 lines
2.4 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(5)
->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']
);
dispatch($singleDelayedJob)->delay(now()->addSeconds($index * 30));
// $delayedJob->delete();
$count++;
}
}
Log::info('ProcessDelayedJobsV2Command Total delayed jobs processed and dispatched: ' . $count);
}
}