diff options
| author | Josh Kearney <josh.kearney@rackspace.com> | 2010-11-19 16:42:37 -0600 |
|---|---|---|
| committer | Josh Kearney <josh.kearney@rackspace.com> | 2010-11-19 16:42:37 -0600 |
| commit | dec8aab1001d85ff7845f7521faf1f610700bd09 (patch) | |
| tree | 4610435c65037f6e4c7c45022d26623d35df9b66 | |
| parent | aa9fe71ed82889f1f3ca306c5836414966d08539 (diff) | |
| download | nova-dec8aab1001d85ff7845f7521faf1f610700bd09.tar.gz nova-dec8aab1001d85ff7845f7521faf1f610700bd09.tar.xz nova-dec8aab1001d85ff7845f7521faf1f610700bd09.zip | |
Reverted some changes
| -rw-r--r-- | nova/rpc.py | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/nova/rpc.py b/nova/rpc.py index cf3889a47..c7ff9ce6b 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -83,35 +83,43 @@ class Consumer(messaging.Consumer): Contains methods for connecting the fetch method to async loops """ def __init__(self, *args, **kwargs): + self.failed_connection = False + while True: try: super(Consumer, self).__init__(*args, **kwargs) break - except: # Catching all because carrot sucks + except: # Catching all because carrot sucks logging.warning("AMQP server on %s:%d is unreachable. " \ "Trying again in 30 seconds." % ( - FLAGS.rabbit_host, - FLAGS.rabbit_port - )) + FLAGS.rabbit_host, + FLAGS.rabbit_port)) time.sleep(30) continue def fetch(self, no_ack=None, auto_ack=None, enable_callbacks=False): """Wraps the parent fetch with some logic for failed connections""" + # TODO(vish): the logic for failed connections and logging should be + # refactored into some sort of connection manager object try: - super(Consumer, self).fetch(no_ack, auto_ack, enable_callbacks) - except: # Catching all because carrot sucks - try: + if self.failed_connection: + # NOTE(vish): conn is defined in the parent class, we can + # recreate it as long as we create the backend too + # pylint: disable-msg=W0201 self.connection = Connection.recreate() self.backend = self.connection.create_backend() self.declare() - except: # Catching all because carrot sucks - logging.warning("AMQP server on %s:%d is unreachable. " \ - "Trying again in 30 seconds." % ( - FLAGS.rabbit_host, - FLAGS.rabbit_port - )) - time.sleep(30) + super(Consumer, self).fetch(no_ack, auto_ack, enable_callbacks) + if self.failed_connection: + logging.error("Reconnected to queue") + self.failed_connection = False + # NOTE(vish): This is catching all errors because we really don't + # exceptions to be logged 10 times a second if some + # persistent failure occurs. + except Exception: # pylint: disable-msg=W0703 + if not self.failed_connection: + logging.exception("Failed to fetch message from queue") + self.failed_connection = True def attach_to_eventlet(self): """Only needed for unit tests!""" |
