取消已经执行的任务与芹菜? [英] Cancel an already executing task with Celery?
问题描述
我一直在阅读文档和搜索,但似乎找不到一个直接的答案:
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 while, and half way through it needs to be cancelled)
我从文档中发现了这个芹菜常见问题
I found this from the doc at Celery FAQ
>>> result = add.apply_async(args=[2, 2], countdown=120)
>>> result.revoke()
但我不清楚这是否会取消排队的任务,否则会杀死对工作人员运行过程。感谢任何光线您可以流下!
But I am unclear if this will cancel queued tasks or if it will kill a running process on a worker. Thanks for any light you can shed!
推荐答案
撤销取消任务执行。如果一个任务被撤销,工作人员将忽略该任务,不执行任务。如果您不使用持续撤销,您的任务可以在工作人员重新启动后执行。
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具有默认为 False 的终止选项。如果您需要终止执行任务,您需要将终止设置为 True 。
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
这篇关于取消已经执行的任务与芹菜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!