Browse Source

Bootsteps: send_all should not propagate errors

Ask Solem 11 years ago
parent
commit
045f86759f
1 changed files with 24 additions and 9 deletions
  1. 24 9
      celery/bootsteps.py

+ 24 - 9
celery/bootsteps.py

@@ -139,25 +139,35 @@ class Blueprint(object):
     def close(self, parent):
         if self.on_close:
             self.on_close()
-        self.send_all(parent, 'close', 'Closing', reverse=False)
+        self.send_all(parent, 'close', 'closing', reverse=False)
 
-    def restart(self, parent, method='stop', description='Restarting'):
-        self.send_all(parent, method, description)
+    def restart(self, parent, method='stop',
+                description='restarting', propagate=False):
+        self.send_all(parent, method, description, propagate=propagate)
 
     def send_all(self, parent, method,
-                 description=None, reverse=True, args=()):
+                 description=None, reverse=True, propagate=True, args=()):
         description = description or method.capitalize()
         steps = reversed(parent.steps) if reverse else parent.steps
         with default_socket_timeout(SHUTDOWN_SOCKET_TIMEOUT):  # Issue 975
             for step in steps:
                 if step:
-                    self._debug('%s %s...', description, step.alias)
+                    self._debug('%s %s...',
+                                description.capitalize(), step.alias)
                     fun = getattr(step, method, None)
                     if fun:
-                        fun(parent, *args)
+                        try:
+                            fun(parent, *args)
+                        except Exception as exc:
+                            if propagate:
+                                raise
+                            logger.error(
+                                'Error while %s %s: %r',
+                                description, step.alias, exc, exc_info=1,
+                            )
 
     def stop(self, parent, close=True, terminate=False):
-        what = 'Terminating' if terminate else 'Stopping'
+        what = 'terminating' if terminate else 'stopping'
         if self.state in (CLOSE, TERMINATE):
             return
 
@@ -168,7 +178,11 @@ class Blueprint(object):
             return
         self.close(parent)
         self.state = CLOSE
-        self.restart(parent, 'terminate' if terminate else 'stop', what)
+
+        self.restart(
+            parent, 'terminate' if terminate else 'stop',
+            description=what, propagate=False,
+        )
 
         if self.on_stopped:
             self.on_stopped()
@@ -371,7 +385,8 @@ class StartStopStep(Step):
         pass
 
     def terminate(self, parent):
-        self.stop(parent)
+        if self.obj:
+            return getattr(self.obj, 'terminate', self.obj.stop)()
 
     def include(self, parent):
         inc, ret = self._should_include(parent)