Skip to content

Commit d718d27

Browse files
committed
Implements new task_retry signal. Closes celery#1169
1 parent 08576ac commit d718d27

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

celery/exceptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ class MaxRetriesExceededError(Exception):
6363
class RetryTaskError(Exception):
6464
"""The task is to be retried later."""
6565

66+
#: Optional message describing context of retry.
67+
message = None
68+
69+
#: Exception (if any) that caused the retry to happen.
70+
exc = None
71+
72+
#: Time of retry (ETA), either int or :class:`~datetime.datetime`.
73+
when = None
74+
6675
def __init__(self, message=None, exc=None, when=None, **kwargs):
6776
from kombu.utils.encoding import safe_repr
6877
self.message = message

celery/signals.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
task_postrun = Signal(providing_args=[
2222
'task_id', 'task', 'args', 'kwargs', 'retval'])
2323
task_success = Signal(providing_args=['result'])
24+
task_retry = Signal(providing_args=[
25+
'request', 'reason', 'einfo',
26+
])
2427
task_failure = Signal(providing_args=[
2528
'task_id', 'exception', 'args', 'kwargs', 'traceback', 'einfo'])
2629
task_revoked = Signal(providing_args=['terminated', 'signum', 'expired'])

celery/task/trace.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ def handle_retry(self, task, store_errors=True):
110110
req = task.request
111111
type_, _, tb = sys.exc_info()
112112
try:
113-
pred = self.retval
114-
einfo = ExceptionInfo((type_, pred, tb))
113+
reason = self.retval
114+
einfo = ExceptionInfo((type_, reason, tb))
115115
if store_errors:
116-
task.backend.mark_as_retry(req.id, pred.exc, einfo.traceback)
117-
task.on_retry(pred.exc, req.id, req.args, req.kwargs, einfo)
116+
task.backend.mark_as_retry(req.id, reason.exc, einfo.traceback)
117+
task.on_retry(reason.exc, req.id, req.args, req.kwargs, einfo)
118+
signals.task_retry.send(sender=task, request=req,
119+
reason=reason, einfo=einfo)
118120
return einfo
119121
finally:
120122
del(tb)

0 commit comments

Comments
 (0)