python - Task dependency in celery -
is such task dependency possible? 1 , 2 can executed in parallel. 1a can executed when 1 finished 12b can executed if both 1 , 2 finished.
i know can create 1 , 2 group, , group(1, 2) | 12b can chain how create 1a starts after 1 finished, no matter going on 2?
yes possible. here 1 way it. used celery signal task_success
connect function triggers celery task
my_tasks.py
from celery import celery, task celery.signals import task_success c = celery('my_tasks') @task def t1(): print('t1') @task def t2(): print('t2') @task def t11(): print('t11') @task def t12(): print('t12') def trigger_task(*args, **kwargs): t11.s().delay() task_success.connect(trigger_task, sender=t1)
testing task:
in [6]: complex_task = chain(group(t1.s(), t2.s())(), t12.si().delay())
here log.
[2014-10-10 12:31:05,082: info/mainprocess] received task: my_tasks.t1[25dc70d2-263b-4e70-b9f2-56478bfedab5] [2014-10-10 12:31:05,083: info/mainprocess] received task: my_tasks.t2[0b0c5eb6-78fa-4900-a605-5bfd55c0d309] [2014-10-10 12:31:05,084: info/mainprocess] received task: my_tasks.t12[b08c616d-7a2d-4f7b-9298-2c8324b747ff] [2014-10-10 12:31:05,084: warning/worker-1] t1 [2014-10-10 12:31:05,084: warning/worker-4] t2 [2014-10-10 12:31:05,085: warning/worker-3] t12 [2014-10-10 12:31:05,086: info/mainprocess] task my_tasks.t2[0b0c5eb6-78fa-4900-a605-5bfd55c0d309] succeeded in 0.00143978099914s: none [2014-10-10 12:31:05,086: info/mainprocess] task my_tasks.t1[25dc70d2-263b-4e70-b9f2-56478bfedab5] succeeded in 0.00191083699974s: none [2014-10-10 12:31:05,087: info/mainprocess] task my_tasks.t12[b08c616d-7a2d-4f7b-9298-2c8324b747ff] succeeded in 0.00184817300033s: none [2014-10-10 12:31:05,087: info/mainprocess] received task: my_tasks.t11[a3e3f0c6-ac1f-4888-893a-02eee3b29585] [2014-10-10 12:31:05,088: warning/worker-2] t11 [2014-10-10 12:31:05,089: info/mainprocess] task my_tasks.t11[a3e3f0c6-ac1f-4888-893a-02eee3b29585] succeeded in 0.000978848000159s: none
i tried connect straight task it throwing error.
python celery django-celery
No comments:
Post a Comment