Browse Source

Pass job.Request instance to task_revoked signal. Closes #1555

Ask Solem 11 years ago
parent
commit
a7226fa158
3 changed files with 13 additions and 3 deletions
  1. 3 1
      celery/signals.py
  2. 2 2
      celery/worker/job.py
  3. 8 0
      docs/userguide/signals.rst

+ 3 - 1
celery/signals.py

@@ -42,7 +42,9 @@ task_retry = Signal(providing_args=[
 task_failure = Signal(providing_args=[
     'task_id', 'exception', 'args', 'kwargs', 'traceback', 'einfo',
 ])
-task_revoked = Signal(providing_args=['terminated', 'signum', 'expired'])
+task_revoked = Signal(providing_args=[
+    'request', 'terminated', 'signum', 'expired',
+])
 celeryd_init = Signal(providing_args=['instance', 'conf'])
 celeryd_after_setup = Signal(providing_args=['instance', 'conf'])
 worker_init = Signal(providing_args=[])

+ 2 - 2
celery/worker/job.py

@@ -288,8 +288,8 @@ class Request(object):
             self.task.backend.mark_as_revoked(self.id, reason)
         self.acknowledge()
         self._already_revoked = True
-        send_revoked(self.task, terminated=terminated,
-                     signum=signum, expired=expired)
+        send_revoked(self.task, request=self,
+                     terminated=terminated, signum=signum, expired=expired)
 
     def revoked(self):
         """If revoked, skip task and mark state."""

+ 8 - 0
docs/userguide/signals.rst

@@ -246,6 +246,14 @@ Sender is the task class revoked/terminated.
 
 Provides arguments:
 
+* request
+
+    This is a :class:`~celery.worker.job.Request` instance, and not
+    ``task.request``.   When using the multiprocessing pool this signal
+    is dispatched in the parent process, so ``task.request`` is not available
+    and should not be used.  Use this object instead, which should have many
+    of the same fields.
+
 * terminated
     Set to :const:`True` if the task was terminated.