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

63 lines
2.0 KiB
PHP

<?php
namespace App\Console\Commands\V2;
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
use Illuminate\Console\Command;
use App\Models\DelayedJob;
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(10)
->get();
$count = 0;
foreach ($jobs as $index => $delayedJob) {
$jobClass = $delayedJob->job_class;
$params = json_decode($delayedJob->parameters, true);
Log::info('ProcessDelayedJobsV2Command packingList : ' . json_encode($params['packingList']));
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']));
$singleDelayedJob = new $jobClass(
$params['packingList'],
$params['transaction'],
$updatePerfexCRMObject,
$params['shouldCreateInvoice']
);
dispatch($singleDelayedJob)->delay(now()->addSeconds($index * 30));
// $delayedJob->delete();
}
Log::info('ProcessDelayedJobsV2Command Total delayed jobs processed and dispatched: ' . $count);
}
}