[英]Celery: Executing a task after another task, but return the result of the first task
Sometimes I need to run task B after task A, but return the result of task A. Looking at the docs, I have tried to ( Avoid launching synchronous subtasks ) 有时我需要在任务A之后运行任务B,但是返回任务A的结果。查看文档,我尝试过( 避免启动同步子任务 )
So I would use a chain, like this: 所以我会使用一条链,像这样:
@celery.task
def A():
return 5
@celery.task
def B():
return 2
def do_all():
chain = A.s() | B.s()
chain()
return result_of_A
But this would not work. 但这行不通。 In my case I need:
就我而言,我需要:
Is it possible to implement this with chains or any other subtasks primitives? 是否可以使用链或任何其他子任务原语来实现此目的?
I can't noodle a way to do this with primitives; 我无法用原始方法来做到这一点; there probably is one.
大概有一个。 But a different approach that would work is, use the
on_success
or after_return
handler in task A to initiate task B. If you also use the ignore_result
option, then the invocation of task B would be truly fire-and-forget. 但是另一种可行的方法是,在任务A中使用
on_success
或after_return
处理程序来启动任务B。如果还使用ignore_result
选项,则对任务B的调用ignore_result
是ignore_result
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.