from celery import chain
@task()
def task_a(a, b):
time.sleep(5)
return a + b
@task()
def task_b(a, b):
time.sleep(5)
return a + b
# the result of the first job will be the first argument of the second job
res = chain(task_a.s(1, 2), task_b.s(3)).apply_async()
# Alternatively, you could do the following
res_2 = (task_a.s(1, 2) | task_b.s(3)).apply_async()
# check ret status to get result
if ret.status == u'SUCCESS':
print "result:", ret.get()
1条答案
按热度按时间goucqfw61#
如果您使用Celery〉v3.0.0,则可以使用链接。
因此,如果希望task_B使用task_a的结果运行,可以执行以下操作。