【问题标题】:Celery task chain cancelling?芹菜任务链取消?
【发布时间】:2012-09-28 03:54:03
【问题描述】:

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

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

例如,我们有一个包含 N 个项目 (N > 2) 的链。在第二个任务中,我们意识到我们不需要执行所有其余的任务。怎么办?

【问题讨论】:

标签: python celery delayed-execution


【解决方案1】:

在较新版本的 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)

【讨论】:

    猜你喜欢
    • 2014-12-04
    • 2014-04-16
    • 2013-02-19
    • 1970-01-01
    • 2011-05-31
    • 2019-08-06
    • 1970-01-01
    • 1970-01-01
    • 2015-01-21
    相关资源
    最近更新 更多