Skip to content

Commit

Permalink
retry_delay is inside pika, adding another one outside
Browse files Browse the repository at this point in the history
  • Loading branch information
silverdaz committed Nov 7, 2018
1 parent 12ccca8 commit cc8df7c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lega/utils/amqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import uuid
from contextlib import contextmanager
import socket
from time import sleep

from ..conf import CONF

Expand Down Expand Up @@ -81,9 +82,10 @@ def connect(self, blocking=True, force=False):

connector = pika.BlockingConnection if blocking else pika.SelectConnection

retry = CONF.get_value('broker', 'retry', conv=int, default=1)
retry = CONF.get_value(self.conf_section, 'retry', conv=int, default=1)
retry_delay = CONF.get_value(self.conf_section,'retry_delay', conv=int, default=10) # seconds
assert retry > 0, "The number of reconnection should be >= 1"
LOG.debug("%d attempts", retry)
LOG.debug("%d attempts [interval: %d]", retry, retry_delay)
count = 0
while count < retry:
count += 1
Expand All @@ -95,13 +97,14 @@ def connect(self, blocking=True, force=False):
return
except (pika.exceptions.ProbableAccessDeniedError,
pika.exceptions.ProbableAuthenticationError,
pika.exceptions.ConnectionClosed) as e:
pika.exceptions.ConnectionClosed,
socket.gaierror) as e:
LOG.debug("MQ connection error: %r", e)
except socket.gaierror as e:
LOG.debug("%s", e)
# except Exception as e:
# LOG.debug("Invalid connection: %r", e)
# break
LOG.debug("Delay %d seconds", retry_delay)
sleep(retry_delay)
except Exception as e:
LOG.debug("Invalid connection: %r", e)
break

# fail to connect
if self.on_failure:
Expand Down

0 comments on commit cc8df7c

Please sign in to comment.