如何安全的停止工作中的队列?(优雅关停)

我一般都是直接kill相关进程,总感觉有点不太对劲。

有没有大佬说一下正确姿势。

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
Summer
最佳答案

启动队列:

queue:work 有个参数 --stop-when-empty 可以让队列运行完成后退出。

运行中的队列

queue:restart 命令会等待队列中的 任务完成后 重启队列(优雅重启)。

此命令同样作用于 Supervisor 运行的 queue:work --daemon,不过需要在 supervisor 的配置中加入 autorestart=true 进行设置。详见 队列 worker & 部署

优雅停止队列

目前 Laravel 8 未提供关闭队列的命令:

$ art | grep queue
  horizon:clear                  Delete all of the jobs from the specified queue
  horizon:forget                 Delete a failed queue job
  horizon:snapshot               Store a snapshot of the queue metrics
 queue
  queue:batches-table            Create a migration for the batches database table
  queue:clear                    Delete all of the jobs from the specified queue
  queue:failed                   List all of the failed queue jobs
  queue:failed-table             Create a migration for the failed queue jobs database table
  queue:flush                    Flush all of the failed queue jobs
  queue:forget                   Delete a failed queue job
  queue:listen                   Listen to a given queue
  queue:restart                  Restart queue worker daemons after their current job
  queue:retry                    Retry a failed queue job
  queue:retry-batch              Retry the failed jobs for a batch
  queue:table                    Create a migration for the queue jobs database table
  queue:work                     Start processing jobs on the queue as a daemon
2年前 评论
讨论数量: 6
Summer

启动队列:

queue:work 有个参数 --stop-when-empty 可以让队列运行完成后退出。

运行中的队列

queue:restart 命令会等待队列中的 任务完成后 重启队列(优雅重启)。

此命令同样作用于 Supervisor 运行的 queue:work --daemon,不过需要在 supervisor 的配置中加入 autorestart=true 进行设置。详见 队列 worker & 部署

优雅停止队列

目前 Laravel 8 未提供关闭队列的命令:

$ art | grep queue
  horizon:clear                  Delete all of the jobs from the specified queue
  horizon:forget                 Delete a failed queue job
  horizon:snapshot               Store a snapshot of the queue metrics
 queue
  queue:batches-table            Create a migration for the batches database table
  queue:clear                    Delete all of the jobs from the specified queue
  queue:failed                   List all of the failed queue jobs
  queue:failed-table             Create a migration for the failed queue jobs database table
  queue:flush                    Flush all of the failed queue jobs
  queue:forget                   Delete a failed queue job
  queue:listen                   Listen to a given queue
  queue:restart                  Restart queue worker daemons after their current job
  queue:retry                    Retry a failed queue job
  queue:retry-batch              Retry the failed jobs for a batch
  queue:table                    Create a migration for the queue jobs database table
  queue:work                     Start processing jobs on the queue as a daemon
2年前 评论

冒然杀死进程可能会带来数据不一致的情况,脚本中如可由外部的因素控制,比如执行前都检查一个文件是否存在或者文件中的标识,让它不继续工作之后,方可以安全的 kill

2年前 评论
  1. 接信号量 处理完当前任务再退出
  2. 用带ACK应答的队列 类似rabbitmq
2年前 评论
circle

php artisan queue:stop?

2年前 评论
胖猪猪 (楼主) 2年前
circle (作者) 2年前
largezhou 2年前
Summer

启动队列:

queue:work 有个参数 --stop-when-empty 可以让队列运行完成后退出。

运行中的队列

queue:restart 命令会等待队列中的 任务完成后 重启队列(优雅重启)。

此命令同样作用于 Supervisor 运行的 queue:work --daemon,不过需要在 supervisor 的配置中加入 autorestart=true 进行设置。详见 队列 worker & 部署

优雅停止队列

目前 Laravel 8 未提供关闭队列的命令:

$ art | grep queue
  horizon:clear                  Delete all of the jobs from the specified queue
  horizon:forget                 Delete a failed queue job
  horizon:snapshot               Store a snapshot of the queue metrics
 queue
  queue:batches-table            Create a migration for the batches database table
  queue:clear                    Delete all of the jobs from the specified queue
  queue:failed                   List all of the failed queue jobs
  queue:failed-table             Create a migration for the failed queue jobs database table
  queue:flush                    Flush all of the failed queue jobs
  queue:forget                   Delete a failed queue job
  queue:listen                   Listen to a given queue
  queue:restart                  Restart queue worker daemons after their current job
  queue:retry                    Retry a failed queue job
  queue:retry-batch              Retry the failed jobs for a batch
  queue:table                    Create a migration for the queue jobs database table
  queue:work                     Start processing jobs on the queue as a daemon
2年前 评论
panda-sir

比如kill -15 你的工作进程worker进程要阻塞SIGTERM这个信号 直至业务代码处理完 再释放这个信号 同时要捕捉SIGTERM 这个信号 进行资源的回收 日志的处理等 下面我贴了下详细的文档

阻塞信号

捕捉信号

2年前 评论

horizon:terminate

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!