通常,最大尝试在队列级别指定,如下所示:
php artisan queue:listen connection-name --tries=3
我希望能够在作业类中的作业级别覆盖此设置(不影响其他作业)。
我可以想到三种方法来解决这个问题,但它们可能并不优雅:
笔记:
最佳答案
尝试使用 attempts()
在作业类中检查当前作业尝试的方法。像下面这样的东西。
class MyJobClass implements ShouldQueue
{
public function handle()
{
if ($this->attempts() < 3) {
// do job things
}
else {
// delete job
}
}
}
laravel 仓库引用 https://github.com/laravel/framework/blob/5.3/src/Illuminate/Queue/InteractsWithQueue.php#L21
关于php - 具有个人最大尝试次数的排队作业,如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40923238/