Created
March 20, 2013 23:19
-
-
Save charlax/5209430 to your computer and use it in GitHub Desktop.
chord returning the header's task group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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