Browse Source

Merge branch 'bobbybeever/master'

Ask Solem 12 years ago
parent
commit
0877e0d79b
2 changed files with 13 additions and 0 deletions
  1. 11 0
      celery/loaders/base.py
  2. 2 0
      celery/worker/__init__.py

+ 11 - 0
celery/loaders/base.py

@@ -45,6 +45,9 @@ class BaseLoader(object):
         * What happens when the worker starts?
             See :meth:`on_worker_init`.
 
+        * What happens when the worker shuts down?
+            See :meth:`on_worker_shutdown`.
+
         * What modules are imported to find tasks?
 
     """
@@ -79,6 +82,11 @@ class BaseLoader(object):
         starts."""
         pass
 
+    def on_worker_shutdown(self):
+        """This method is called when the worker (:program:`celery worker`)
+        shuts down."""
+        pass
+
     def on_worker_process_init(self):
         """This method is called when a child process starts."""
         pass
@@ -107,6 +115,9 @@ class BaseLoader(object):
             self.import_default_modules()
             self.on_worker_init()
 
+    def shutdown_worker(self):
+        self.on_worker_shutdown()
+
     def init_worker_process(self):
         self.on_worker_process_init()
 

+ 2 - 0
celery/worker/__init__.py

@@ -403,6 +403,8 @@ class WorkController(configurated):
         if self._state in (self.CLOSE, self.TERMINATE):
             return
 
+        self.app.loader.shutdown_worker()
+
         if self.pool:
             self.pool.close()