简体   繁体   中英

Filtering and deleting tasks from Celery

We are using celery with redis.

We had some wrong celery architecture implemented in our project. So tasks were being added to celery faster than they were being processed. So the queue became larger and larger.

We have changed the design of our project, and it will not happen hereafter.

But celery has a large backlog which I want to remove. To be precise we have 800000 backlogged tasks in a queue.

We have a single queue but two different types of tasks have been added to this queue. We have a task named func_a and another name func_b. The queue contains 300000 of func_a and 500000 of func_b.

I want to remove all occurences func_a from the queue. What is the simplest way to accomplish this?

something like this should do it:

from path.to.your.tasks import app

i = app.control.inspect()

for worker, jobs in i.scheduled().iteritems():
    for job in jobs:
        if job['task_name'] == 'path.to.your.tasks.func_a'
            app.AsyncResult(job['id']).revoke()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM