How to inspect and cancel Celery tasks by task name

前端 未结 4 792
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-12 15:55

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?

<
4条回答
  •  半阙折子戏
    2020-12-12 16:24

    # 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)
    

提交回复
热议问题