laravel queue work 参数

Laravel queue work 参数

问题:laravel 执行队列如果失败,没有增加重试限制的话,会无限尝试,导致消耗服务器资源,磁盘空间爆满。

参数介绍:

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

--daemon

命令包含一个--daemon选项,用于强制队列工作者在不重新启动框架的情况下继续处理作业。与队列:listen命令相比,这大大减少了CPU使用量

--quiet
不输出任何内容

--queue=default
队列名称

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

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

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

实际应用:

这里配置了最尝试次数3次,如果失败后,队列的延迟执行配置秒数自行配置(如果失败了,没有延迟执行的话,会在短时间内马上执行3次重试,这里加上延迟增加了缓冲的时间)。

php artisan queue:work --delay=秒数 --tries=3

php artisan quque:work 参数说明 Illuminate\Queue\Console\WorkCommand.php

queue:work
{connection? : The name of the queue connection to work}
{--queue= : The names of the queues to work}
{--daemon : Run the worker in daemon mode (Deprecated)}
{--once : Only process the next job on the queue}
{--delay=0 : The number of seconds to delay failed jobs}
{--force : Force the worker to run even in maintenance mode}
{--memory=128 : The memory limit in megabytes}
{--sleep=3 : Number of seconds to sleep when no job is available}
{--timeout=60 : The number of seconds a child process can run}
{--tries=0 : Number of times to attempt a job before logging it failed}

 

posted @ 2022-07-15 14:11  丶老中医  阅读(890)  评论(0)    收藏  举报
一切已经开始©2018 丶老中医