Cancel an already executing task with Celery?

后端 未结 5 1547
轻奢々
轻奢々 2020-11-27 09:57

I have been reading the doc and searching but cannot seem to find a straight answer:

Can you cancel an already executing task? (as in the task has started, takes a w

5条回答
  •  再見小時候
    2020-11-27 10:37

    In Celery 3.1, the API of revoking tasks is changed.

    According to the Celery FAQ, you should use result.revoke:

    >>> result = add.apply_async(args=[2, 2], countdown=120)
    >>> result.revoke()
    

    or if you only have the task id:

    >>> from proj.celery import app
    >>> app.control.revoke(task_id)
    

提交回复
热议问题