前景需求:在我们用队列的时候发现maxtries的个数时255次,这个太影响其他队列任务
我目前使用的thinkphp版本是6.1
第一部定义一个新的类
CustomDataBase(我用的mysql数据库存放的队列)
重写__make 和createPlainPayload方法
<?php
namespace app;
use think\Db;
use think\queue\connector\Database;
class CustomDataBase extends Database
{
// 此方法必须有,具体原因自己看源码吧
public static function __make(Db $db, $config)
{
$connection = $db->connect($config['connection'] ?? null);
return new self($connection, $config['table'], $config['queue'], $config['retry_after'] ?? 60);
}
protected function createPlainPayload($job, $data)
{
return [
'job' => $job,
'maxTries' => 22,
'timeout' => null,
'data' => $data,
];
}
}
第二步修改queue.php文件的配置

为什么要重写类,自己要点Queue::push(),查看源码,因为我的项目通篇用的都是用的类名,最简单的是重写,当然你也可以自己在push的时候写对象,对象里面定义属性$tries=10;
Queue::push(EmailJob::class, $email->id);

