简体   繁体   English

芹菜任务链取消?

[英]Celery task chain cancelling?

I found that celery supports task chains: http://celery.readthedocs.org/en/latest/userguide/canvas.html#chains . 我发现芹菜支持任务链: http//celery.readthedocs.org/en/latest/userguide/canvas.html#chains

Question is: how can I stop chain's execution in a task? 问题是: 如何在任务中停止链的执行?

For example, we got a chain of N items (N > 2). 例如,我们得到了一个N​​项链(N> 2)。 And in the second task we realize that we do not need all the rest tasks to be executed. 在第二个任务中,我们意识到我们不需要执行所有其余任务。 What to do? 该怎么办?

In newer versions of celery (3.1.6) you can revoke an entire chain by simply walking the chain and revoking each item in turn. 在较新版本的芹菜(3.1.6)中,您可以通过简单地走链并依次撤销每个项目来撤销整个链。

# Build a chain for results
from tasks import addd
from celery import chain

def revoke_chain(result):
    while result:
        result.revoke()
        result = result.parent

# independent tasks (with immutable signatures)
c = chain(*tuple(add.si(i,i) for i in xrange(50)))
h = c()

# some time later ...
revoke_chain(h)

# dependant task
c = add.s(1,1) | add.s(2) | add.s(3)
h = c()

# some time later ...
revoke_chain(h)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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