芹菜任务链取消? [英] Celery task chain cancelling?

查看:123
本文介绍了芹菜任务链取消?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I found that celery supports task chains: http://celery.readthedocs.org/en/latest/userguide/canvas.html#chains.

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

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

For example, we got a chain of N items (N > 2). And in the second task we realize that we do not need all the rest tasks to be executed. What to do?

推荐答案

在较新版本的芹菜(3.1.6)中,您只需走动链条就可以撤销整个链条

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.

# 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)

这篇关于芹菜任务链取消?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆