2

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)

Vahid Kharazi
  • 5,723
  • 17
  • 60
  • 103
  • 1
    if `a=A.apply_async(params)` etc, did you try to `(a | group(b, (c | d), (e | f | g))` ? – ItayB Nov 08 '17 at 21:00
  • @ItayB Thanks, I need something like your comment. The result of `a` function will pass to `b` but how can I pass the result of `a` to `c` and `e`? – Vahid Kharazi Nov 11 '17 at 08:23
  • actually I never tried this scenario, are you sure that it wont? did u try? in theory, because it's a group `c` can start before `b` and also `e`, are you sure that only the first one in the `group` gets the previous result? – ItayB Nov 11 '17 at 19:57
  • @ItayB 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`. – Vahid Kharazi Nov 12 '17 at 12:32
  • @ItayB Please write your solution (`(a | group(b, (c | d), (e | f | g))`) as an answer :) – Vahid Kharazi Nov 12 '17 at 12:34
  • I'm not sure it is, I'll have to test it first. I can suggest workaround if you like.. – ItayB Nov 13 '17 at 18:56

1 Answers1

1

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.

ItayB
  • 10,377
  • 9
  • 50
  • 77