Search code examples
pythonasynchronouscelerycelery-taskcelery-canvas

Setting a signature of a task as starting task of multipe chain in celery


Suppose A to G are async tasks and we want to implement a task workflow like this canvas

     /---> B()
A()  ----> C() -> D()
     \---> E() -> F() -> G()

According to the problem, we need to use the result of A() for starting of multiple chains.

In code:

from celery import chain

# A (params) ?????

B.apply_async(params)
chain(
    C.s(params), D.s(params)
).apply_async()
chain(
    E.s(params), F.s(params), G.s(params)
).apply_async()

In the Celery Canvas, how can I use the result of A() to first elements of multiple chains asynchronously without run the A() three times?

(I'm using the Celery 4.1.0 and RabbitMQ as a broker)


Solution

  • I know! b, c, e not preserve order but surely a will done before all of them because there is a chain. I just want to use the return value of a as input parameters of b, c and e.