I Have add some wrong task
to a celery
with redis broker
but now I want to remove the incorrect task
and I can't find any way to do this
Is there some commands or some api to do this ?
I Have add some wrong task
to a celery
with redis broker
but now I want to remove the incorrect task
and I can't find any way to do this
Is there some commands or some api to do this ?
I know two ways of doing so:
1) Delete queue directly from broker. In your case it's Redis. There are two commands that could help you: llen (to find right queue) and del (to delete it).
2) Start celery worker with --purge or --discard options. Here is help:
--purge, --discard Purges all waiting tasks before the daemon is started.
**WARNING**: This is unrecoverable, and the tasks will
be deleted from the messaging server.
The simplest way is to use the celery control revoke [id1 [id2 [... [idN]]]]
(do not forget to pass the -A project.application
flag too). Where id1 to idN are task IDs. However, it is not guaranteed to succeed every time you run it, for valid reasons...
Sure Celery has API for it. Here is an example how to do it from a script: res = app.control.revoke(task_id, terminate=True)
In the example above app
is an instance of the Celery application.
In some rare ocasions the control command above will not work, in which case you have to instruct Celery worker to kill the worker process: res = app.control.revoke(task_id, terminate=True, signal='SIGKILL')
I just had this problem so for future readers,
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().
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):
2 ... and then purge the tasks from a specific queue:
$ cd <source_dir
$ celery amqp queue.purge <queue name>
3. Start workers again
try to remove the .state file and if you are using a beat worker (celery worker -B) then remove the schedule file as well