我试图在Laravel中使用Queues延迟。我永远无法延迟工作,所有工作都立即解雇。
我在config / queue.php和.env中将驱动程序设置为“数据库”我还使用php artisan创建了作业表并进行了迁移。运行php工匠队列:工作或队列:listen具有相同的效果,工作立即触发。
我在我的数据库中看到,在jobs表中,字段“available_at”和“created_at”实际上都包含相同的时间戳,忽略了我在代码中放入的延迟:
$job = (new ParkingMatchJob($this->seller,$this->job_counter+1))->delay(Carbon::now()->addSeconds(20));
$this->dispatch($job);
我也尝试过:
$job = (new ParkingMatchJob($this->seller,$this->job_counter+1))->delay(20);
$this->dispatch($job);
无济于事。
我在laravel.log或php_error.log中没有看到任何错误
如果你能帮助我,我会提前感谢你。
我认为派遣的顺序不正确。
它应该在delay()之前:
ParkingMatchJob::dispatch($this->seller,$this->job_counter+1)->delay(Carbon::now()->addSeconds(20));