Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inspect and cancel Celery tasks by task name

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.

like image 874
Mzzzzzz Avatar asked Mar 22 '13 16:03

Mzzzzzz


People also ask

How do I cancel a task on Celery?

To cancel an already executing task with Celery and Python, we can use the revoke function. to call revoke with the task_id of the task to stop. And we set terminate to True to terminate the task.

Can a celery task call another task?

To answer your opening questions: As of version 2.0, Celery provides an easy way to start tasks from other tasks. What you are calling "secondary tasks" are what it calls "subtasks".

Where are Celery tasks stored?

In Celery, a result back end is a place where, when you call a Celery task with a return statement, the task results are stored. Choosing the right results back end can potentially save you hours of pain later.


1 Answers

# 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) 
like image 150
gioi Avatar answered Sep 27 '22 23:09

gioi