【问题标题】:Understanding Job and job table in Laravel?了解 Laravel 中的作业和作业表?
【发布时间】:2015-07-30 06:20:16
【问题描述】:

我在 laravel5.1 中使用job

首先我通过运行 artisan 命令创建了一个表job,如下所示。

php artisan queue:table
php artisan migrate // You forgot this

我也写了job class

php artisan make:job RecordAttendanceJob --queued
class RecordAttendanceJob extends Job implements SelfHandling, ShouldQueue {
 -------------
 ------------- 
}

dispatch 这个来自控制器,如下所示并且工作正常,

  $job = (new RecordAttendanceJob($attArray));
  $this->dispatch($job);

这是我的疑问,

  • 为什么使用那个作业表,我发现那个作业表总是空的?
  • 以后向用户通知作业成功/失败的最佳方式是什么?
  • 我也找到了以下方法,Queue::push(new RecordAttendanceJob($attArray))。这和dispatch 工作有什么区别?哪种方法更好?

【问题讨论】:

  • 除了官方的 laravel 5.1 文档,我建议你也阅读这篇文章:laravelcoding.com/blog/… 我认为它很好地解释了队列和作业的工作原理,包括各种队列驱动程序。由于在您的情况下作业表始终为空,我猜您仍在使用默认同步驱动程序,它会立即同步处理项目
  • @KristofM 我已经更新了配置,现在出现错误DOStatement::execute(): MySQL server has gone away........ 系统试图将垃圾值插入表job

标签: php laravel laravel-5 jobs laravel-5.1


【解决方案1】:

对于作业失败时的通知,请将失败的函数添加到作业类中,该方法将在作业失败时运行。 (http://laravel.com/docs/5.1/queues#failed-job-events)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 2019-11-13
    • 1970-01-01
    相关资源
    最近更新 更多