删除芹菜中所有待处理的任务?
在不知道每个任务的 task_id
的情况下,如何删除所有待处理任务?
How can I delete all pending tasks without knowing the task_id
for each task?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
在不知道每个任务的 task_id
的情况下,如何删除所有待处理任务?
How can I delete all pending tasks without knowing the task_id
for each task?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(12)
来自 文档:
或
(编辑:使用当前方法更新。)
From the docs:
or
(EDIT: Updated with current method.)
对于 celery 3.0+:
要清除特定队列:
For celery 3.0+:
To purge a specific queue:
对于 Celery 2.x 和 3.x:
例如,当使用带有 -Q 参数的工作程序来定义队列时,
celery purge
将不起作用,因为您无法将队列参数传递给它。它只会删除默认队列。解决方案是使用
--purge
参数启动工作程序,如下所示:但这将运行工作程序。
其他选项是使用 celery 的 amqp 子命令
For Celery 2.x and 3.x:
When using worker with -Q parameter to define queues, for example
then
celery purge
will not work, because you cannot pass the queue params to it. It will only delete the default queue.The solution is to start your workers with
--purge
parameter like this:This will however run the worker.
Other option is to use the amqp subcommand of celery
在 Celery 3+ 中:
CLI:
以编程方式:
http:// /docs.celeryproject.org/en/latest/faq.html#how-do-i-purge-all-waiting-tasks
In Celery 3+:
CLI:
Programatically:
http://docs.celeryproject.org/en/latest/faq.html#how-do-i-purge-all-waiting-tasks
我发现 celery purge 不适用于我更复杂的 celery 配置。我将多个命名队列用于不同的目的:
第一列是队列名称,第二列是队列中等待的消息数量,第三列是该队列的侦听器数量。这些队列是:
分析任务是一种强力任务,在小型数据集上效果很好,但现在需要超过 24 小时才能处理。有时,会出现问题,并且会卡在等待数据库上。它需要重写,但在那之前,当它卡住时,我会终止任务,清空队列,然后重试。我通过查看分析队列的消息计数来检测“卡住”,该计数应该为 0(已完成分析)或 1(等待昨晚的分析完成)。 2 或更高是不好的,我收到一封电子邮件。
celery purge 可以从广播队列之一中删除任务,但我没有看到选择不同命名队列的选项。
这是我的过程:
I found that
celery purge
doesn't work for my more complex celery config. I use multiple named queues for different purposes:The first column is the queue name, the second is the number of messages waiting in the queue, and the third is the number of listeners for that queue. The queues are:
The analytics task is a brute force tasks that worked great on small data sets, but now takes more than 24 hours to process. Occasionally, something will go wrong and it will get stuck waiting on the database. It needs to be re-written, but until then, when it gets stuck I kill the task, empty the queue, and try again. I detect "stuckness" by looking at the message count for the analytics queue, which should be 0 (finished analytics) or 1 (waiting for last night's analytics to finish). 2 or higher is bad, and I get an email.
celery purge
offers to erase tasks from one of the broadcast queues, and I don't see an option to pick a different named queue.Here's my process:
如果您想删除所有挂起的任务以及活动和保留的任务以完全停止 Celery,这对我有用:
If you want to remove all pending tasks and also the active and reserved ones to completely stop Celery, this is what worked for me:
在 Celery 3+ 中
http:// /docs.celeryproject.org/en/3.1/faq.html#how-do-i-purge-all-waiting-tasks
CLI
清除命名队列:
清除配置的队列
因此,要清除整个队列,必须停止工作人员。
In Celery 3+
http://docs.celeryproject.org/en/3.1/faq.html#how-do-i-purge-all-waiting-tasks
CLI
Purge named queue:
Purge configured queue
So to purge the entire queue workers must be stopped.
对于 Celery 5.0+,要从 CLI 执行此操作并定位特定队列:
celery -A APP_NAME purge --queues QUEUE_NAME
将
-f
选项添加到末尾以跳过如果您想像我一样在步骤中执行此操作,请执行确认步骤。For Celery 5.0+, to do it from the CLI and to target a specific queue:
celery -A APP_NAME purge --queues QUEUE_NAME
Add
-f
option to the end to skip the confirmation step if you're trying to do it in on step like I was.芹菜4+
celery purge 命令以
编程方式清除所有配置的任务队列:
所有挂起的任务都将被清除。
参考: 芹菜文档
celery 4+
celery purge command to purge all configured task queues
programmatically:
all pending task will be purged.
Reference: celerydoc
对于以 RabbitMQ 作为代理的 Celery 版本 5.0+
我们需要首先建立从程序到代理的新连接,
并将连接与要清除的队列绑定。
For Celery Version 5.0+ with RabbitMQ as broker
We need establish a new connection from program to broker first,
and bind the connection with the queues to purge.
1.
要正确清除等待任务队列,您必须停止所有工作人员(http://celery.readthedocs.io/en/latest/faq.html#i-ve-purged-messages-but-there-are-still-messages-left-in-the-queue ):
或(如果 RabbitMQ/消息代理由 Supervisor 管理):
2.
...然后从特定队列中清除任务:
3.
启动 RabbitMQ:
或(如果 RabbitMQ 由 Supervisor 管理):
1.
To properly purge the queue of waiting tasks you have to stop all the workers (http://celery.readthedocs.io/en/latest/faq.html#i-ve-purged-messages-but-there-are-still-messages-left-in-the-queue):
or (in case RabbitMQ/message broker is managed by Supervisor):
2.
...and then purge the tasks from a specific queue:
3.
Start RabbitMQ:
or (in case RabbitMQ is managed by Supervisor):
我想这可能已经解决了。旧任务仍然在我的 django 管理中的 django-celery-beat> 定期任务中,所以转到 django 管理页面并删除所有这些,然后如果您在 docker 容器中,重新启动它,所有问题都解决了
I think that may have solved it. the old tasks were still in django-celery-beat>periodic tasks in my django admin, so go to django admin page and delete all of them, then if you are in docker container, restart the it all the problem solved