Set and use AMQP retry interval and max retry constants

This commit is contained in:
Josh Kearney
2010-11-22 14:45:05 -06:00
parent e92ec42295
commit 242db7aebd

View File

@@ -38,8 +38,11 @@ from nova import fakerabbit
from nova import flags from nova import flags
from nova import context from nova import context
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
AMQP_RETRY_INT = 10
AMQP_MAX_RETRIES = 12
LOG = logging.getLogger('amqplib') LOG = logging.getLogger('amqplib')
LOG.setLevel(logging.DEBUG) LOG.setLevel(logging.DEBUG)
@@ -85,16 +88,22 @@ class Consumer(messaging.Consumer):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.failed_connection = False self.failed_connection = False
while True: for i in range(AMQP_MAX_RETRIES):
try: try:
super(Consumer, self).__init__(*args, **kwargs) super(Consumer, self).__init__(*args, **kwargs)
break break
except: # Catching all because carrot sucks except: # Catching all because carrot sucks
logging.exception("AMQP server on %s:%d is unreachable. " \ if i + 1 == AMQP_MAX_RETRIES:
"Trying again in 30 seconds." % ( 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_host,
FLAGS.rabbit_port)) FLAGS.rabbit_port,
time.sleep(30) AMQP_RETRY_INT))
time.sleep(AMQP_RETRY_INT)
continue continue
def fetch(self, no_ack=None, auto_ack=None, enable_callbacks=False): def fetch(self, no_ack=None, auto_ack=None, enable_callbacks=False):
@@ -103,7 +112,7 @@ class Consumer(messaging.Consumer):
# refactored into some sort of connection manager object # refactored into some sort of connection manager object
try: try:
if self.failed_connection: if self.failed_connection:
# NOTE(vish): conn is defined in the parent class, we can # NOTE(vish): connection is defined in the parent class, we can
# recreate it as long as we create the backend too # recreate it as long as we create the backend too
# pylint: disable-msg=W0201 # pylint: disable-msg=W0201
self.connection = Connection.recreate() self.connection = Connection.recreate()