芹菜任务链取消?

Nik*_*tov 9 python delayed-execution celery

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

问题是:如何在任务中停止链的执行?

例如,我们得到了一个N​​项链(N> 2).在第二个任务中,我们意识到我们不需要执行所有其余任务.该怎么办?

And*_*ker 5

在较新版本的 celery (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)
Run Code Online (Sandbox Code Playgroud)