fix config handling
This commit is contained in:
parent
ac5cbf1682
commit
261224311c
1 changed files with 19 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue