forked from platypush/platypush
Removed short circuit on the response
This commit is contained in:
parent
6c7c08f7aa
commit
cb423dab03
2 changed files with 8 additions and 7 deletions
|
@ -57,7 +57,8 @@ def _init_plugin(plugin_name, reload=False):
|
||||||
return plugin
|
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
|
origin = args.pop('origin') if 'origin' in args else None
|
||||||
action = args.pop('action')
|
action = args.pop('action')
|
||||||
tokens = action.split('.')
|
tokens = action.split('.')
|
||||||
|
@ -81,17 +82,17 @@ def _exec_func(args, backend=None, retry=True):
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
if retry:
|
if retry:
|
||||||
# Put the popped args back where they were before retrying
|
# 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))
|
logging.info('Reloading plugin {} and retrying'.format(module_name))
|
||||||
_init_plugin(module_name, reload=True)
|
_init_plugin(module_name, reload=True)
|
||||||
_exec_func(args, backend, retry=False)
|
_exec_func(args, retry=False)
|
||||||
finally:
|
finally:
|
||||||
if backend: backend.send_response(origin, response)
|
if backend: backend.send_response(origin, response)
|
||||||
|
|
||||||
|
|
||||||
def on_msg(msg, backend=None):
|
def on_msg(msg):
|
||||||
Thread(target=_exec_func, args=(msg,backend)).start()
|
Thread(target=_exec_func, args=(msg,)).start()
|
||||||
|
|
||||||
|
|
||||||
def parse_config_file(config_file=None):
|
def parse_config_file(config_file=None):
|
||||||
|
@ -216,7 +217,7 @@ Usage: {} [-v] [-h] [-c <config_file>]
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
on_msg(mq.get(), backend)
|
on_msg(mq.get())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ class Backend(Thread):
|
||||||
self.on_error('No action specified: {}'.format(msg))
|
self.on_error('No action specified: {}'.format(msg))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
msg['backend'] = self # Augment message
|
||||||
self.mq.put(msg)
|
self.mq.put(msg)
|
||||||
|
|
||||||
def send_msg(self, msg):
|
def send_msg(self, msg):
|
||||||
|
@ -72,7 +73,6 @@ class Backend(Thread):
|
||||||
'a dictionary but received {}'.format(type(msg)))
|
'a dictionary but received {}'.format(type(msg)))
|
||||||
|
|
||||||
msg['origin'] = self.device_id # To get the response
|
msg['origin'] = self.device_id # To get the response
|
||||||
|
|
||||||
self._send_msg(msg)
|
self._send_msg(msg)
|
||||||
|
|
||||||
def send_response(self, target, response):
|
def send_response(self, target, response):
|
||||||
|
|
Loading…
Reference in a new issue