【发布时间】:2019-04-10 13:12:52
【问题描述】:
我有一个带有队列的 Laravel 项目,每天运行约 1000 个作业。
当作业失败时,在 5.7 中,它被移动到 failed_jobs 表,我可以重试它。
迁移到 Laravel 5.8 后,作业就消失了。
此代码应将作业标记为失败并将其放入 failed-jobs 表中。
/**
* Execute the job.
*/
public function handle()
{
throw new \Exception('WRONG JOB');
}
这种情况下的主管日志:
[2019-04-10 15:07:57][11932] Processing: App\Jobs\ExecuteAction
好像执行停止了,没有调用Queue::failing事件。
此代码有效,但对我来说似乎不正确。
class ExecuteAction implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Execute the job.
*/
public function handle()
{
try {
throw new \Exception('WROOONG');
} catch (\Exception $e) {
if ($this->attempts() < $this->tries) {
$this->release(10);
} else {
$this->fail($e);
}
}
}
}
Queue::failing 事件被调用。
主管日志;
[2019-04-10 15:06:52][11926] Processing: App\Jobs\ExecuteAction
[2019-04-10 15:06:52][11926] Failed: App\Jobs\ExecuteAction
[2019-04-10 15:06:52][11926] Processed: App\Jobs\ExecuteAction
在主管配置中
command=php /path/to/laravel-project/artisan queue:listen
我做错了什么?
感谢您的帮助。
【问题讨论】:
-
您使用的是什么队列驱动程序?
-
嗨,我正在使用
database。 -
如果您不指定 --tries 选项。该作业将永远不会存储在失败的表中...
-
@shock_gone_wild 阅读文档后并不明显,但通过查看框架中的 Worker 代码,您似乎是对的。该文档还解释说我可以在我的工作类中使用
public $tries = 5;,但它似乎没有使用。 -
据我所知,public $tries = 5 正在工作。我只是通过指定 --tries=2 而没有指定 --tries ind worker 命令对其进行了测试。在这两种情况下,在 5 次尝试后,作业都会发送到失败的作业表
标签: laravel laravel-queue laravel-5.8