Cancel an already executing task with Celery?

后端 未结 5 1560
轻奢々
轻奢々 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:22

    revoke cancels the task execution. If a task is revoked, the workers ignore the task and do not execute it. If you don't use persistent revokes your task can be executed after worker's restart.

    http://docs.celeryproject.org/en/latest/userguide/workers.html#worker-persistent-revokes

    revoke has an terminate option which is False by default. If you need to kill the executing task you need to set terminate to True.

    >>> from celery.task.control import revoke
    >>> revoke(task_id, terminate=True)
    

    http://docs.celeryproject.org/en/latest/userguide/workers.html#revoke-revoking-tasks

提交回复
热议问题