|
@@ -112,15 +112,19 @@ class BaseBackend(object):
|
|
|
"""Mark a task as started"""
|
|
|
return self.store_result(task_id, meta, status=states.STARTED)
|
|
|
|
|
|
- def mark_as_done(self, task_id, result, request=None):
|
|
|
+ def mark_as_done(self, task_id, result, request=None, state=states.SUCCESS):
|
|
|
"""Mark task as successfully executed."""
|
|
|
- return self.store_result(task_id, result,
|
|
|
- status=states.SUCCESS, request=request)
|
|
|
+ self.store_result(task_id, result, status=state, request=request)
|
|
|
+ if request and request.chord:
|
|
|
+ self.on_chord_part_return(request, state)
|
|
|
|
|
|
- def mark_as_failure(self, task_id, exc, traceback=None, request=None):
|
|
|
+ def mark_as_failure(self, task_id, exc,
|
|
|
+ traceback=None, request=None, state=states.FAILURE):
|
|
|
"""Mark task as executed with failure. Stores the exception."""
|
|
|
- return self.store_result(task_id, exc, status=states.FAILURE,
|
|
|
- traceback=traceback, request=request)
|
|
|
+ self.store_result(task_id, exc, status=state,
|
|
|
+ traceback=traceback, request=request)
|
|
|
+ if request and request.chord:
|
|
|
+ self.on_chord_part_return(request, state, exc)
|
|
|
|
|
|
def chord_error_from_stack(self, callback, exc=None):
|
|
|
from celery import group
|
|
@@ -346,7 +350,7 @@ class BaseBackend(object):
|
|
|
def add_to_chord(self, chord_id, result):
|
|
|
raise NotImplementedError('Backend does not support add_to_chord')
|
|
|
|
|
|
- def on_chord_part_return(self, task, state, result, propagate=False):
|
|
|
+ def on_chord_part_return(self, request, state, result, propagate=False):
|
|
|
pass
|
|
|
|
|
|
def fallback_chord_unlock(self, group_id, body, result=None,
|
|
@@ -540,20 +544,20 @@ class KeyValueStoreBackend(BaseBackend):
|
|
|
|
|
|
return header(*partial_args, task_id=group_id, **fixed_options or {})
|
|
|
|
|
|
- def on_chord_part_return(self, task, state, result, propagate=None):
|
|
|
+ def on_chord_part_return(self, request, state, result, propagate=None):
|
|
|
if not self.implements_incr:
|
|
|
return
|
|
|
app = self.app
|
|
|
if propagate is None:
|
|
|
propagate = app.conf.CELERY_CHORD_PROPAGATES
|
|
|
- gid = task.request.group
|
|
|
+ gid = request.group
|
|
|
if not gid:
|
|
|
return
|
|
|
key = self.get_key_for_chord(gid)
|
|
|
try:
|
|
|
- deps = GroupResult.restore(gid, backend=task.backend)
|
|
|
+ deps = GroupResult.restore(gid, backend=self)
|
|
|
except Exception as exc:
|
|
|
- callback = maybe_signature(task.request.chord, app=app)
|
|
|
+ callback = maybe_signature(request.chord, app=app)
|
|
|
logger.error('Chord %r raised: %r', gid, exc, exc_info=1)
|
|
|
return self.chord_error_from_stack(
|
|
|
callback,
|
|
@@ -563,7 +567,7 @@ class KeyValueStoreBackend(BaseBackend):
|
|
|
try:
|
|
|
raise ValueError(gid)
|
|
|
except ValueError as exc:
|
|
|
- callback = maybe_signature(task.request.chord, app=app)
|
|
|
+ callback = maybe_signature(request.chord, app=app)
|
|
|
logger.error('Chord callback %r raised: %r', gid, exc,
|
|
|
exc_info=1)
|
|
|
return self.chord_error_from_stack(
|
|
@@ -576,7 +580,7 @@ class KeyValueStoreBackend(BaseBackend):
|
|
|
logger.warning('Chord counter incremented too many times for %r',
|
|
|
gid)
|
|
|
elif val == size:
|
|
|
- callback = maybe_signature(task.request.chord, app=app)
|
|
|
+ callback = maybe_signature(request.chord, app=app)
|
|
|
j = deps.join_native if deps.supports_native_join else deps.join
|
|
|
try:
|
|
|
with allow_join_result():
|