瀏覽代碼

Merge pull request #2658 from natw/no_retries

consumer should not retry connection when BROKER_CONNECTION_RETRY is False
Omer Katz 10 年之前
父節點
當前提交
8af4c7eb09
共有 2 個文件被更改,包括 11 次插入0 次删除
  1. 7 0
      celery/tests/worker/test_consumer.py
  2. 4 0
      celery/worker/consumer.py

+ 7 - 0
celery/tests/worker/test_consumer.py

@@ -115,6 +115,13 @@ class test_Consumer(AppCase):
             c.start()
             sleep.assert_called_with(1)
 
+    def test_no_retry_raises_error(self):
+        self.app.conf.BROKER_CONNECTION_RETRY = False
+        c = self.get_consumer()
+        c.blueprint.start.side_effect = socket.error()
+        with self.assertRaises(socket.error):
+            c.start()
+
     def _closer(self, c):
         def se(*args, **kwargs):
             c.blueprint.state = CLOSE

+ 4 - 0
celery/worker/consumer.py

@@ -277,6 +277,10 @@ class Consumer(object):
             try:
                 blueprint.start(self)
             except self.connection_errors as exc:
+                # If we're not retrying connections, no need to catch
+                # connection errors
+                if not self.app.conf.BROKER_CONNECTION_RETRY:
+                    raise
                 if isinstance(exc, OSError) and exc.errno == errno.EMFILE:
                     raise  # Too many open files
                 maybe_shutdown()