Detecting when a celery task and all subtasks are completed

I have a parent task that will spawn an arbitrary and potentially quite large number of subtasks. Once the parent and all the subtasks are complete, I need to set a flag in my database to indicate that it is ready. How am I best to do this?

For instance:

@task()
def master_task(foo):
    foo_obj = Foo.objects.get(id=foo)
    for bar in foo_obj.bar_set.all():
        more_work.delay(bar.id)

@task()
def more_work(bar):
   bar_obj = Bar.objects.get(id=bar)
   do_work()

I need to determine when master_task and all the subtasks that it has completed are complete, so that I can set a flag in the corresponding model to indicate that everything is ready

+5
source share
2 answers

Use chords

[TaskSet] [1]: > TaskSet , . >
+4
+2

All Articles