【问题标题】:Delayed Queued job fires immediately with database driver使用数据库驱动程序立即触发延迟的排队作业
【发布时间】: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\Queueable trait吗?

标签: php laravel


【解决方案1】:

我认为调度的顺序不正确。

应该在delay()之前:

ParkingMatchJob::dispatch($this->seller,$this->job_counter+1)->delay(Carbon::now()->addSeconds(20));

【讨论】:

    猜你喜欢
    • 2015-09-14
    • 2015-09-04
    • 2017-12-02
    • 1970-01-01
    • 2015-02-18
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多