Removed short circuit on the response

This commit is contained in:
Fabio Manganiello 2017-12-16 07:01:25 +01:00
parent 6c7c08f7aa
commit cb423dab03
2 changed files with 8 additions and 7 deletions

View File

@ -57,7 +57,8 @@ def _init_plugin(plugin_name, reload=False):
return plugin
def _exec_func(args, backend=None, retry=True):
def _exec_func(args, retry=True):
backend = args.pop('backend') if 'backend' in args else None
origin = args.pop('origin') if 'origin' in args else None
action = args.pop('action')
tokens = action.split('.')
@ -81,17 +82,17 @@ def _exec_func(args, backend=None, retry=True):
logging.exception(e)
if retry:
# Put the popped args back where they were before retrying
args['action'] = action; args['origin'] = origin
args['action'] = action; args['origin'] = origin; args['backend'] = backend
logging.info('Reloading plugin {} and retrying'.format(module_name))
_init_plugin(module_name, reload=True)
_exec_func(args, backend, retry=False)
_exec_func(args, retry=False)
finally:
if backend: backend.send_response(origin, response)
def on_msg(msg, backend=None):
Thread(target=_exec_func, args=(msg,backend)).start()
def on_msg(msg):
Thread(target=_exec_func, args=(msg,)).start()
def parse_config_file(config_file=None):
@ -216,7 +217,7 @@ Usage: {} [-v] [-h] [-c <config_file>]
while True:
try:
on_msg(mq.get(), backend)
on_msg(mq.get())
except KeyboardInterrupt:
return

View File

@ -62,6 +62,7 @@ class Backend(Thread):
self.on_error('No action specified: {}'.format(msg))
return
msg['backend'] = self # Augment message
self.mq.put(msg)
def send_msg(self, msg):
@ -72,7 +73,6 @@ class Backend(Thread):
'a dictionary but received {}'.format(type(msg)))
msg['origin'] = self.device_id # To get the response
self._send_msg(msg)
def send_response(self, target, response):