From 261224311c16136143b5b001836b6f9382c9628a Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Oct 05 2017 20:15:23 +0000 Subject: fix config handling --- diff --git a/plugins/hub/messagebus.py b/plugins/hub/messagebus.py index a561c4b..93a5b63 100644 --- a/plugins/hub/messagebus.py +++ b/plugins/hub/messagebus.py @@ -69,8 +69,23 @@ class Connection(qpid.messaging.Connection): timeout = self._timeout return qpid.messaging.Connection._wait(self, predicate, timeout) + +def get_config(): + global config + if config: + return config + + config = ConfigParser.SafeConfigParser() + config.read(CONFIG_FILE) + if not config.has_option('broker', 'timeout'): + config.set('broker', 'timeout', '60') + if not config.has_option('broker', 'heartbeat'): + config.set('broker', 'heartbeat', '60') + return config + + def get_sender(): - global config, session, target + global session, target if session and target: try: return session.sender(target) @@ -79,12 +94,7 @@ def get_sender(): session = None target = None - config = ConfigParser.SafeConfigParser() - config.read(CONFIG_FILE) - if not config.has_option('broker', 'timeout'): - config.set('broker', 'timeout', '60') - if not config.has_option('broker', 'heartbeat'): - config.set('broker', 'heartbeat', '60') + config = get_config() if config.getboolean('broker', 'ssl'): url = 'amqps://' @@ -206,7 +216,6 @@ def get_message_headers(msgtype, *args, **kws): @ignore_error @convert_datetime def prep_message(cbtype, *args, **kws): - global config if cbtype.startswith('post'): msgtype = cbtype[4:] else: @@ -216,6 +225,7 @@ def prep_message(cbtype, *args, **kws): if args: data['args'] = list(args) + config = get_config() exchange_type = config.get('exchange', 'type') if exchange_type == 'topic': subject = get_message_subject(msgtype, *args, **kws) @@ -236,7 +246,7 @@ def prep_message(cbtype, *args, **kws): def send_messages(cbtype, *args, **kws): '''Send the messages cached by prep_message''' - global config + config = get_config() messages = getattr(context, 'messagebus_plugin_messages', []) if not messages: return