diff options
author | Josh Kearney <josh.kearney@rackspace.com> | 2010-11-22 15:22:02 -0600 |
---|---|---|
committer | Josh Kearney <josh.kearney@rackspace.com> | 2010-11-22 15:22:02 -0600 |
commit | 14e4ba7f0e10fc3c2f532b445c1f656f53c8aa95 (patch) | |
tree | caf61fbd40c57ce52f0ebfd9670c3cd8f16971b8 | |
parent | 51be7159574d3e0cba8a81b8ea3e9706ce74ac3a (diff) | |
download | nova-14e4ba7f0e10fc3c2f532b445c1f656f53c8aa95.tar.gz nova-14e4ba7f0e10fc3c2f532b445c1f656f53c8aa95.tar.xz nova-14e4ba7f0e10fc3c2f532b445c1f656f53c8aa95.zip |
Refactor AMQP retry loop
-rw-r--r-- | nova/rpc.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/nova/rpc.py b/nova/rpc.py index c2d18cb61..961b56de6 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -86,25 +86,25 @@ class Consumer(messaging.Consumer): Contains methods for connecting the fetch method to async loops """ def __init__(self, *args, **kwargs): - self.failed_connection = False - - for i in range(AMQP_MAX_RETRIES): + for i in xrange(AMQP_MAX_RETRIES): + if i > 0: + time.sleep(AMQP_RETRY_INT) try: super(Consumer, self).__init__(*args, **kwargs) + self.failed_connection = False break except: # Catching all because carrot sucks - if i + 1 == AMQP_MAX_RETRIES: - logging.exception("Unable to connect to AMQP server" \ - " after %d tries. Shutting down." % AMQP_MAX_RETRIES) - sys.exit(1) - else: - logging.exception("AMQP server on %s:%d is unreachable." \ - " Trying again in %d seconds." % ( - FLAGS.rabbit_host, - FLAGS.rabbit_port, - AMQP_RETRY_INT)) - time.sleep(AMQP_RETRY_INT) - continue + logging.exception("AMQP server on %s:%d is unreachable." \ + " Trying again in %d seconds." % ( + FLAGS.rabbit_host, + FLAGS.rabbit_port, + AMQP_RETRY_INT)) + self.failed_connection = True + continue + if self.failed_connection: + logging.exception("Unable to connect to AMQP server" \ + " after %d tries. Shutting down." % AMQP_MAX_RETRIES) + sys.exit(1) def fetch(self, no_ack=None, auto_ack=None, enable_callbacks=False): """Wraps the parent fetch with some logic for failed connections""" |