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

61 lines
1.7 KiB
PHP

<?php
namespace App\Console\Commands\V2;
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);
$singleDelayedJob = new $jobClass(
$params['packingList'],
$params['transaction'],
$params['updatePerfexCRMObject'],
$params['shouldCreateInvoice']
);
Log::info('ProcessDelayedJobsV2Command packingList : ' . $params['packingList']);
Log::info('ProcessDelayedJobsV2Command transaction : ' . $params['transaction']);
Log::info('ProcessDelayedJobsV2Command updatePerfexCRMObject : ' . $params['updatePerfexCRMObject']);
Log::info('ProcessDelayedJobsV2Command shouldCreateInvoice : ' . $params['shouldCreateInvoice']);
dispatch($singleDelayedJob)->delay(now()->addSeconds($index * 30));
// $delayedJob->delete();
}
Log::info('ProcessDelayedJobsV2Command Total delayed jobs processed and dispatched: ' . $count);
}
}