I have around 10,000 scheduled tasks on my current celery setup. I didn\'t realize what scheduled tasks were and decided to use them to send follow-up emails months in advan
1. To properly purge the queue of waiting tasks you have MUST 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):
$ sudo rabbitmqctl stop
or (in case RabbitMQ/message broker is managed by Supervisor):
$ sudo supervisorctl stop all
2. ...and then purge the tasks from a specific queue:
$ cd <source_dir>
$ celery amqp queue.purge <queue name>
3. Start RabbitMQ:
$ sudo rabbitmqctl start
or (in case RabbitMQ is managed by Supervisor):
$ sudo supervisorctl start all
If you have only been using one queue or one task, this is easy:
From the docs:
Answer: You can use the celery purge command to purge all configured task queues:
$ celery -A proj purge
or programatically:
>>> from proj.celery import app
>>> app.control.purge()
1753
If you only want to purge messages from a specific queue you have to use the AMQP API or the celery amqp utility:
$ celery -A proj amqp queue.purge <queue name>
The number 1753 is the number of messages deleted.
You can also start worker with the --purge
argument, to purge messages when the worker starts.
Update: If you have multiple queues or tasks
I don't know of any way to edit them in RabbitMQ since the server is not built to access/edit/delete queued tasks that way, but you could always disable your task in the code:
@task
def my_old_task()
pass
This way all the tasks will run as scheduled but won't perform anything; since they are neither renamed nor deleted, you won't have any error.
Obviously you should update your code to stop scheduling these tasks. After a while, there won't be anymore tasks of this type scheduled so you can delete the code.