【发布时间】:2017-11-06 04:02:48
【问题描述】:
我正在尝试延迟使用 Laravel 中的队列。我永远无法延迟上班,所有的工作都被立即解雇了。
我在 config/queue.php 和 .env 中都将驱动程序设置为“数据库” 我还使用 php artisan 创建了作业表并进行了迁移。 运行 php artisan queue:work 或 queue:listen 具有相同的效果,作业会立即触发。
我在我的数据库中看到,在作业表中,字段“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 中没有看到任何错误
如果你能帮助我,我提前感谢你。
【问题讨论】:
-
你在你的类
ParkingMatchJob中实现了ShouldQueue接口吗? -
类ParkingMatchJob实现ShouldQueue
-
使用 Dispatchable、InteractsWithQueue、Queueable、SerializesModels;
-
您是否尝试过仅使用辅助调度功能?不确定这是否能解决问题,但您可以尝试删除
$this->dispatch($job)而是尝试dispatch($job); -
你在使用
Illuminate\Bus\Queueabletrait吗?