I’m using Celery (3.0.15) with Redis as a broker.
Is there a straightforward way to query the number of tasks with a given name that exist in a Celery queue?
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.
Advertisement
Answer
JavaScript
x
9
1
# Retrieve tasks
2
# Reference: http://docs.celeryproject.org/en/latest/reference/celery.events.state.html
3
query = celery.events.state.tasks_by_type(your_task_name)
4
5
# Kill tasks
6
# Reference: http://docs.celeryproject.org/en/latest/userguide/workers.html#revoking-tasks
7
for uuid, task in query:
8
celery.control.revoke(uuid, terminate=True)
9