Skip to content

Instantly share code, notes, and snippets.

@charlax
Created March 20, 2013 23:19
Show Gist options
  • Save charlax/5209430 to your computer and use it in GitHub Desktop.
Save charlax/5209430 to your computer and use it in GitHub Desktop.
chord returning the header's task group
class ProgressChord(chord):
"""
Chord that returns both the callback's AsyncResult and the group's
AsyncResult.
"""
# See:
# http://stackoverflow.com/questions/15441101/how-to-track-the-progress-of-individual-tasks-inside-a-group-which-forms-the-hea
# https://groups.google.com/forum/?fromgroups=#!topic/celery-users/xSdxI-Z08Cw
def __call__(self, body=None, **kwargs):
# Taken from celery source code, celery.canvas
_chord = self.Chord
body = (body or self.kwargs['body']).clone()
kwargs = dict(self.kwargs, body=body, **kwargs)
if _chord.app.conf.CELERY_ALWAYS_EAGER:
return self.apply((), kwargs)
callback_id = body.options.setdefault('task_id', uuid())
r = _chord(**kwargs)
return _chord.AsyncResult(callback_id), r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment