Explorar o código

Added new loaded handler: on_task_return

Ask Solem %!s(int64=15) %!d(string=hai) anos
pai
achega
c261fff721
Modificáronse 2 ficheiros con 8 adicións e 0 borrados
  1. 4 0
      celery/loaders/base.py
  2. 4 0
      celery/worker/job.py

+ 4 - 0
celery/loaders/base.py

@@ -28,6 +28,10 @@ class BaseLoader(object):
         """This method is called before a task is executed."""
         pass
 
+    def on_task_return(self, task_id, task, status, retval):
+        """This method is called after a task is executed."""
+        pass
+
     def on_worker_init(self):
         """This method is called when the worker (``celeryd``) starts."""
         pass

+ 4 - 0
celery/worker/job.py

@@ -105,6 +105,10 @@ class WorkerTaskTrace(TaskTrace):
             self.task.backend.mark_as_done(self.task_id, retval)
         return self.super.handle_success(retval, *args)
 
+    def handle_after_return(self, status, retval, type_, tb, strtb):
+        self.loader.on_task_return(self.task_id, self.task, status, retval)
+        self.super.handle_after_return(status, retval, type_, tb, strtb)
+
     def handle_retry(self, exc, type_, tb, strtb):
         """Handle retry exception."""
         message, orig_exc = exc.args