1

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)

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:

  • B does not have any parameter. It does not accept the result of A
  • B must be executed after A completes
  • I do not need to wait for B to complete, and I do not need its result (B must be async?)
  • How do I return the result of A in do_all? (A must be sync?)

Is it possible to implement this with chains or any other subtasks primitives?

4

1 回答 1

0

我无法用原语来做这件事。可能有一个。但是另一种可行的方法是,使用任务 A 中的on_successorafter_return处理程序来启动任务 B。如果您还使用该ignore_result选项,那么任务 B 的调用将是真正的即发即弃。

于 2013-08-26T19:19:26.063 回答