如何按任务名称检查和取消 Celery 任务 [英] How to inspect and cancel Celery tasks by task name
本文介绍了如何按任务名称检查和取消 Celery 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 Celery (3.0.15) 和 Redis 作为代理.
I'm using Celery (3.0.15) with Redis as a broker.
是否有一种直接的方法可以查询 Celery 队列中存在的给定名称的任务数量?
Is there a straightforward way to query the number of tasks with a given name that exist in a Celery queue?
并且,作为后续,有没有办法取消 Celery 队列中存在的所有具有给定名称的任务?
And, as a followup, is there a way to cancel all tasks with a given name that exist in a Celery queue?
我已经阅读了监控和管理指南在那里看不到解决方案.
I've been through the Monitoring and Management Guide and don't see a solution there.
推荐答案
# Retrieve tasks
# Reference: http://docs.celeryproject.org/en/latest/reference/celery.events.state.html
query = celery.events.state.tasks_by_type(your_task_name)
# Kill tasks
# Reference: http://docs.celeryproject.org/en/latest/userguide/workers.html#revoking-tasks
for uuid, task in query:
celery.control.revoke(uuid, terminate=True)
这篇关于如何按任务名称检查和取消 Celery 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文