求助:队列任务失败后为什么没有重试呀?
1. 运行环境
1). 当前使用的 Laravel 版本?
8.75
2). 当前使用的 php/php-fpm 版本?
PHP 版本:8.0
3). 当前系统
CentOS 7
2. 问题描述?
最近写了个队列任务,再线上运行着,最近发现失败了不会自动重试啦,之前有没有重试也没注意,暂时没找到原因,请有经验的大哥给看看什么原因造成的?每次修改代码都重启supervisor啦。
class CashRewardDetail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* 任务可尝试次数.
*
* @var int
*/
public $tries = 7;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
if (SUCCESS) {
} else {
$this->fail();
return;
}
}
public function backoff()
{
return [2, 5, 10, 20, 30, 60];
}
}
[program:queue]
command=/www/server/php/80/bin/php /www/wwwroot/host/artisan queue:listen --queue=多个队列名称
directory=/www/wwwroot/host/
autorestart=true
startsecs=3
startretries=3
stdout_logfile=/www/server/panel/plugin/supervisor/log/queue.out.log
stderr_logfile=/www/server/panel/plugin/supervisor/log/queue.err.log
stdout_logfile_maxbytes=2MB
stderr_logfile_maxbytes=2MB
user=www
priority=999
numprocs=1
process_name=%(program_name)s_%(process_num)02d
看失败队列里面的信息,failed_jobs
找到原因啦,任务失败不能执行:$this->fail();,要throw 一个错误才可以后续继续重试!谢谢大家!