通常,我使用supervisor
处理queues
。不过它很先进,而且有很多article/support
发布了其配置,您可以轻松找到它们。
我正在跟进Laravel 文章中的这个主管配置 https://rohit-shirke.medium.com/configuring-supervisor-for-laravel-queues-81e555e550c6
这对我来说非常有效,我已经配置了很多 Laravel 项目queues
通过它。它还具有许多内置选项来处理queue-failure
, restarting
等等。此外,我们可以运行多个workers
在最短的时间内轻松使用它。它是process handling
方法非常优化并且有据可查。
基本安装流程:
管理 Laravel 队列或任何需要在服务器上运行的托管进程
sudo apt-get install supervisor
加载目录cd /etc/supervisor/conf.d
并创建一个配置文件my-project-worker.conf
并添加以下配置
[program:<custom-worker-name>]
command=<project-directory-path>/artisan queue:work --tries=3 --sleep=3
directory=<project-directory-path i.e /var/www/html/example-project>
stdout_logfile=<custom-path-to-store-log i.e /var/www/html/example-project/storage/logs/supervisord.log>
redirect_stderr=true
autostart=true
autorestart=true
numprocs=1
stopwaitsecs=3600
## For Multiple Workers ##
[program:%(<custom-worker-name>)s_%(process_num)02d]
command=<project-directory-path>/artisan queue:work --tries=3 --sleep=3
directory=<project-directory-path i.e /var/www/html/example-project>
stdout_logfile=<custom-path-to-store-log i.e /var/www/html/example-project/storage/logs/supervisord.log>
redirect_stderr=true
autostart=true
autorestart=true
numprocs=3
stopwaitsecs=3600
Note:确保设置<custom-worker-name>
, <project-directory-path>
and <custom-path-to-store-log>
根据你的项目。
Remember当您部署包含对现有作业代码的修改的新代码时,您需要重新启动主管进程或该特定作业。
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start <custom-worker-name>:*
要检查正在运行的主管进程:
sudo supervisorctl
要检查进程的状态:
sudo systemctl status supervisor
要停止该进程:
sudo systemctl stop supervisor