上线之后订单通知不发了,redis 里 LLEN queues:default 一直涨,两小时堆到 8000 多。supervisorCtl status 看进程是 RUNNING,日志里却只有一行 exited: queue:work (exit status 1; not expected)。
先看 supervisor 配置。command 写的是 php /www/app/artisan queue:work,没带 --queue,也没带 --tries。日志只配了 stdout_logfile,stderr 没接,真正的异常根本没落盘。加上 redirect_stderr=true 重跑,报的是 Connection refused [tcp://127.0.0.1:6379]。
可 redis 明明是通的,redis-CLI ping 返回 PONG。问题在配置缓存:部署脚本跑了 php artisan config:cache,缓存里 REDIS_HOST 还是上一版的内网地址 172.16.3.21。config:clear 之后手动跑一次 queue:work,任务立刻开始消费。这类事在 CI 里很常见,配置改了缓存没清。
[program:laravel-worker]
command=php /www/app/artisan queue:work redis
--queue=high,default --tries=3 --timeout=90
process_name=%(program_name)s_%(process_num)02d
numprocs=4
stopwaitsecs=3600
redirect_stderr=true
stdout_logfile=/var/log/worker.log
supervisor 还有两个参数容易漏。stopwaitsecs 默认 10 秒,queue:work 收到 SIGTERM 要等当前 job 跑完,长任务会被直接 kill,表现就是任务做了一半。我设成 3600。numprocs 按压力给,默认 1 个进程,8000 条积压就是它一条条啃。
另外 config/queue.php 里 redis 的 retry_after 必须大于 queue:work 的 --timeout。如果反了,任务没跑完就被重新投递,同一个订单发两次通知。我这边设 retry_after 120、timeout 90。
改完清缓存、重启 supervisor,积压 20 分钟消化完。现在部署脚本固定两步:config:cache 之后必跟 queue:restart,不然 worker 还跑着旧代码。
