소스 검색

[worker][consumer] Consumer.start silenced some connection errors

Ask Solem 9 년 전
부모
커밋
3d72919992
1개의 변경된 파일16개의 추가작업 그리고 6개의 파일을 삭제
  1. 16 6
      celery/worker/consumer/consumer.py

+ 16 - 6
celery/worker/consumer/consumer.py

@@ -302,15 +302,25 @@ class Consumer(object):
                 except RestartFreqExceeded as exc:
                     crit('Frequent restarts detected: %r', exc, exc_info=1)
                     sleep(1)
-                if blueprint.state != CLOSE and self.connection:
-                    warn(CONNECTION_RETRY, exc_info=True)
-                    try:
-                        self.connection.collect()
-                    except Exception:
-                        pass
+                if blueprint.state != CLOSE:
+                    if self.connection:
+                        self.on_connection_error_after_connected(exc)
+                    else:
+                        self.on_connection_error_before_connected(exc)
                     self.on_close()
                     blueprint.restart(self)
 
+    def on_connection_error_before_connected(self, exc):
+        error(CONNECTION_ERROR, self.conninfo.as_uri(), exc,
+              'Trying to reconnect...')
+
+    def on_connection_error_after_connected(self, exc):
+        warn(CONNECTION_RETRY, exc_info=True)
+        try:
+            self.connection.collect()
+        except Exception:
+            pass
+
     def register_with_event_loop(self, hub):
         self.blueprint.send_all(
             self, 'register_with_event_loop', args=(hub,),