python - How to use the return value of the first task in the second task's group for loop? -
i have 2 celery tasks:
@app.task def task1(a, b, c, d): # stuff , find return value return r @app.task def task2(a, b, c, d, e, f, g): # other stuff
i want first execute task1 , execute group of task2 in parallel:
c = chain(task1.s(a, b, c, d), group(task2.si(a, b, c, e, i, j) i, j in enumerate(range(e))))
but, "e" argument above return value of task1, passed task2 , used in loop. how implemented using celery?
you may specify base first task , have call second task retval of first. can in on_success method of base.
import task celery def setval(): return 1, 2, 3 class followup(task): def on_success(self, retval, task_id, *args, **kwargs): i, j in enumerate(range(retval)): task2.si(a, b, c, retval, i, j) # a, b, c should set before here # use task set here if need collectively verify status of tasks # http://docs.celeryproject.org/en/2.1-archived/reference/celery.task.sets.html @app.task(base=followuptask) def add(*args): return 3 @app.task def task2(a, b, c, d, e, f, g): pass
Comments
Post a Comment