美文网首页
laravel job 配置 supervisord

laravel job 配置 supervisord

作者: 师娘哪里去了 | 来源:发表于2019-12-06 11:19 被阅读0次

安装过程略...
配置文件:

#usr/local/etc/supervisord.ini
#balabalaba 系统默认配置略...
...
[include]
files = /usr/local/etc/supervisor.d/*.ini

配置子项目配置文件:

#/usr/local/etc/supervisor.d/the9edu-paper-exam.ini
[program:the9edu-paper-exam]
process_name=%(program_name)s_%(process_num)02d
command=php /Users/nick/workspace/php/project/gjd/resource-the9edu-com/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=nick
numprocs=3
redirect_stderr=true
stdout_logfile=/Users/nick/workspace/php/project/gjd/resource-the9edu-com/storage/logs/the9edu-paper-exam-worker.log

参考配置说明:

[program:idea]                          ; 是应用程序的唯一标识,不能重复
directory = /data/jidea-server          ; 程序的启动目录
command = /data/jidea-server/IntelliJIDEALicenseServer_darwin_amd64 ; 启动命令
autostart = true                        ; 在 supervisord 启动的时候也自动启动
startsecs = 5                           ; 启动 5 秒后没有异常退出,就当作已经正常启动了
autorestart = true                      ; 程序异常退出后自动重启
startretries = 3                        ; 启动失败自动重试次数,默认是 3
redirect_stderr = true                  ; 把 stderr 重定向到 stdout,默认 false
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /var/log/supervusor/jidea-server.log   ; stdout 日志文件,注意:要确保目录已经建立并且可以访问(写权限)

查看状态:

supervisorctl status

Laravel 命令

php artisan queue:work --daemon --quiet --queue=default --delay=3 --sleep=3 --tries=3

--daemon

The queue:work Artisan command includes a --daemon option for forcing the queue worker to continue processing jobs without ever re-booting the framework. This results in a significant reduction of CPU usage when compared to the queue:listen command

总体来说,在 supervisor 中一般要加这个 option,可以节省 CPU 使用。

--quiet

不输出任何内容

--delay=3

一个任务失败后,延迟多长时间后再重试,单位是秒。这个值的设定我个人建议不要太短,因为一个任务失败(比如网络原因),重试时间太短可能会出现连续失败的情况。

--sleep=3

去 Redis 中拿任务的时候,发现没有任务,休息多长时间,单位是秒。这个值的设定要看你的任务是否紧急,如果是那种非常紧急的任务,不能等待太长时间。

--tries=3

定义失败任务最多重试次数。这个值的设定根据任务的重要程度来确定,一般 3 次比较适合。

相关文章

网友评论

      本文标题:laravel job 配置 supervisord

      本文链接:https://www.haomeiwen.com/subject/wpwsgctx.html