I have a parent task that will spawn an arbitrary and potentially largish number of subtasks. Once both the parent and all of the subtasks have completed I need to set a flag in my database to indicate that it's ready. How would I best go about doing that?
For example:
@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 detect when the master_task and all of the subtasks it has spawns have completed so that I can set a flag on a related model to indicate that everything is ready
Use chords
celery.chord is designed precisely for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With