我如何删除所有挂起的任务,而不知道每个任务的task_id ?
当前回答
芹菜4 + 芹菜清除命令清除所有已配置的任务队列
celery -A *APPNAME* purge
编程:
from proj.celery import app
app.control.purge()
所有挂起的任务将被清除。 参考:celerydoc
其他回答
如果你想删除所有挂起的任务,以及活动和保留的任务,以完全停止Celery,这对我来说是有效的:
from proj.celery import app
from celery.task.control import inspect, revoke
# remove pending tasks
app.control.purge()
# remove active tasks
i = inspect()
jobs = i.active()
for hostname in jobs:
tasks = jobs[hostname]
for task in tasks:
revoke(task['id'], terminate=True)
# remove reserved tasks
jobs = i.reserved()
for hostname in jobs:
tasks = jobs[hostname]
for task in tasks:
revoke(task['id'], terminate=True)
芹菜4 + 芹菜清除命令清除所有已配置的任务队列
celery -A *APPNAME* purge
编程:
from proj.celery import app
app.control.purge()
所有挂起的任务将被清除。 参考:celerydoc
对于芹菜5.0+,从CLI执行该操作,并针对特定的队列:
—APP_NAME清除——QUEUE_NAME
如果你想像我一样在一个步骤中做,那么在最后添加-f选项来跳过确认步骤。
1. 要正确清除等待任务的队列,您必须停止所有的worker (http://celery.readthedocs.io/en/latest/faq.html#i-ve-purged-messages-but-there-are-still-messages-left-in-the-queue):
$ sudo rabbitmqctl stop
或者(如果RabbitMQ/消息代理由Supervisor管理):
$ sudo supervisorctl stop all
2. ...然后清除特定队列中的任务:
$ cd <source_dir>
$ celery amqp queue.purge <queue name>
3. RabbitMQ开始:
$ sudo rabbitmqctl start
或者(如果RabbitMQ由Supervisor管理):
$ sudo supervisorctl start all
芹菜3+
http://docs.celeryproject.org/en/3.1/faq.html#how-do-i-purge-all-waiting-tasks
CLI
清除命名队列:
celery -A proj amqp queue.purge <queue name>
清除配置的队列
celery -A proj purge
I’ve purged messages, but there are still messages left in the queue? Answer: Tasks are acknowledged (removed from the queue) as soon as they are actually executed. After the worker has received a task, it will take some time until it is actually executed, especially if there are a lot of tasks already waiting for execution. Messages that are not acknowledged are held on to by the worker until it closes the connection to the broker (AMQP server). When that connection is closed (e.g. because the worker was stopped) the tasks will be re-sent by the broker to the next available worker (or the same worker when it has been restarted), so to properly purge the queue of waiting tasks you have to stop all the workers, and then purge the tasks using celery.control.purge().
因此,要清除整个队列,必须停止worker。
推荐文章
- 重新安装后无法访问RabbitMQ web管理界面
- UI线程上的任务继续
- 删除芹菜/ rabbitmq中所有挂起的任务
- 任务有什么用。FromResult< result >
- rails耙任务是否提供对ActiveRecord模型的访问?
- 为什么我们需要像RabbitMQ这样的消息代理而不是像PostgreSQL这样的数据库?
- 为什么使用异步和返回等待,当你可以直接返回任务<T> ?
- 等待不同结果的多个任务
- 正确使用任务时。运行,当只是async-await
- 任务与线程的差异
- 如何安全地调用c#异步方法没有等待
- 何时在Kafka上使用RabbitMQ ?
- ActiveMQ或RabbitMQ或ZeroMQ或