thinkphp6 queue队列的maxTries自定义

前景需求:在我们用队列的时候发现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);
相关推荐
AIgorithmGEEK6 小时前
MySQL 索引全解(下):建、查、删实战与知识速查表
数据库·mysql·b+树·索引
Best-Wishes7 小时前
科来网络分析系统(技术交流版)使用说明书
开发语言·junit·php
唠点键盘之外的8 小时前
26 向量数据库实战:从 0 搭一条能用的检索链路(pgvector + Spring AI)
数据库·人工智能·spring
云和恩墨8 小时前
数据库监控简史:监控不止于告警——从图表大爆发到健康管理闭环
数据库
ly76898 小时前
MongoDB 事务开销实测:快照隔离下的写冲突、重试与分片事务边界
数据库·mongodb·事务·分片集群·快照隔离·写冲突
豆角焖肉8 小时前
Spring AOP 自定义注解实现系统操作日志
数据库·自定义注解·springaop·操作日志·aop 切面
爱上网的小舟9 小时前
星际战士2启动错误怎么办?5种游戏报错解决方法
开发语言·php
金伟API102410 小时前
不会写复杂SQL怎么办?
数据库·sql
执笔为剑10 小时前
2.1.2-1、V8R3迁移到V8R6-Oracle兼容特性
数据库
geovindu10 小时前
sql:Search-Optimized SQL Queries using mysql 9.0
android·数据库·sql·mysql·数据库开发·数据库架构