Better fix for broken async variables and attributes after Python 3.7 migration

This commit is contained in:
Fabio Manganiello 2018-08-07 22:00:11 +00:00
parent ee5e4dff92
commit 822e0a1e25
5 changed files with 21 additions and 21 deletions

View file

@ -239,7 +239,7 @@ class HttpBackend(Backend):
if isinstance(msg, Request): if isinstance(msg, Request):
try: try:
response = msg.execute(async=False) response = msg.execute(_async=False)
except PermissionError: except PermissionError:
abort(401) abort(401)

View file

@ -148,10 +148,10 @@ class Config(object):
self.cronjobs[cron_name] = self._config[key] self.cronjobs[cron_name] = self._config[key]
elif key.startswith('procedure.'): elif key.startswith('procedure.'):
tokens = key.split('.') tokens = key.split('.')
async = True if tokens[1] == 'async' else False _async = True if tokens[1] == 'async' else False
procedure_name = '.'.join(tokens[2:]) procedure_name = '.'.join(tokens[2:])
self.procedures[procedure_name] = { self.procedures[procedure_name] = {
'async': async, '_async': _async,
'actions': self._config[key] 'actions': self._config[key]
} }
else: else:

View file

@ -27,7 +27,7 @@ class Cronjob(Thread):
context = {} context = {}
for action in self.actions: for action in self.actions:
response = action.execute(async=False, **context) response = action.execute(_async=False, **context)
logger.info('Response from cronjob {}: {}'.format(self.name, response)) logger.info('Response from cronjob {}: {}'.format(self.name, response))

View file

@ -71,7 +71,7 @@ class Request(Message):
proc_name = self.action.split('.')[-1] proc_name = self.action.split('.')[-1]
proc_config = Config.get_procedures()[proc_name] proc_config = Config.get_procedures()[proc_name]
proc = Procedure.build(name=proc_name, requests=proc_config['actions'], proc = Procedure.build(name=proc_name, requests=proc_config['actions'],
async=proc_config['async'], _async=proc_config['_async'],
backend=self.backend, id=self.id) backend=self.backend, id=self.id)
return proc.execute(*args, **kwargs) return proc.execute(*args, **kwargs)
@ -159,12 +159,12 @@ class Request(Message):
'origin attached: {}'.format(response)) 'origin attached: {}'.format(response))
def execute(self, n_tries=1, async=True, **context): def execute(self, n_tries=1, _async=True, **context):
""" """
Execute this request and returns a Response object Execute this request and returns a Response object
Params: Params:
n_tries -- Number of tries in case of failure before raising a RuntimeError n_tries -- Number of tries in case of failure before raising a RuntimeError
async -- If True, the request will be run asynchronously and the _async -- If True, the request will be run asynchronously and the
response posted on the bus when available (default), response posted on the bus when available (default),
otherwise the current thread will wait for the response otherwise the current thread will wait for the response
to be returned synchronously. to be returned synchronously.
@ -212,7 +212,7 @@ class Request(Message):
if self.token is None or get_hash(self.token) != token_hash: if self.token is None or get_hash(self.token) != token_hash:
raise PermissionError() raise PermissionError()
if async: if _async:
Thread(target=_thread_func, args=(n_tries,)).start() Thread(target=_thread_func, args=(n_tries,)).start()
else: else:
return _thread_func(n_tries) return _thread_func(n_tries)

View file

@ -11,17 +11,17 @@ logger = logging.getLogger(__name__)
class Procedure(object): class Procedure(object):
""" Procedure class. A procedure is a pre-configured list of requests """ """ Procedure class. A procedure is a pre-configured list of requests """
def __init__(self, name, async, requests, backend=None): def __init__(self, name, _async, requests, backend=None):
""" """
Params: Params:
name -- Procedure name name -- Procedure name
async -- Whether the actions in the procedure are supposed to _async -- Whether the actions in the procedure are supposed to
be executed sequentially or in parallel (True or False) be executed sequentially or in parallel (True or False)
requests -- List of platylist.message.request.Request objects requests -- List of platylist.message.request.Request objects
""" """
self.name = name self.name = name
self.async = async self._async = _async
self.requests = requests self.requests = requests
self.backend = backend self.backend = backend
@ -30,7 +30,7 @@ class Procedure(object):
@classmethod @classmethod
def build(cls, name, async, requests, backend=None, id=None, **kwargs): def build(cls, name, _async, requests, backend=None, id=None, **kwargs):
reqs = [] reqs = []
loop_count = 0 loop_count = 0
if_count = 0 if_count = 0
@ -47,11 +47,11 @@ class Procedure(object):
# A 'for' loop is synchronous. Declare a 'fork' loop if you # A 'for' loop is synchronous. Declare a 'fork' loop if you
# want to process the elements in the iterable in parallel # want to process the elements in the iterable in parallel
async = True if m.group(1) == 'fork' else False _async = True if m.group(1) == 'fork' else False
iterator_name = m.group(2) iterator_name = m.group(2)
iterable = m.group(3) iterable = m.group(3)
loop = LoopProcedure.build(name=loop_name, async=async, loop = LoopProcedure.build(name=loop_name, _async=_async,
requests=request_config[key], requests=request_config[key],
backend=backend, id=id, backend=backend, id=id,
iterator_name=iterator_name, iterator_name=iterator_name,
@ -87,7 +87,7 @@ class Procedure(object):
request = Request.build(request_config) request = Request.build(request_config)
reqs.append(request) reqs.append(request)
return cls(name=name, async=async, requests=reqs, backend=backend, **kwargs) return cls(name=name, _async=_async, requests=reqs, backend=backend, **kwargs)
def execute(self, n_tries=1, **context): def execute(self, n_tries=1, **context):
@ -105,10 +105,10 @@ class Procedure(object):
if token: if token:
request.token = token request.token = token
context['async'] = self.async; context['n_tries'] = n_tries context['_async'] = self._async; context['n_tries'] = n_tries
response = request.execute(**context) response = request.execute(**context)
if not self.async: if not self._async:
if isinstance(response.output, dict): if isinstance(response.output, dict):
for (k,v) in response.output.items(): for (k,v) in response.output.items():
context[k] = v context[k] = v
@ -145,15 +145,15 @@ class LoopProcedure(Procedure):
context = {} context = {}
def __init__(self, name, iterator_name, iterable, requests, async=False, backend=None, **kwargs): def __init__(self, name, iterator_name, iterable, requests, _async=False, backend=None, **kwargs):
super(). __init__(name=name, async=async, requests=requests, backend=None, **kwargs) super(). __init__(name=name, _async=_async, requests=requests, backend=None, **kwargs)
self.iterator_name = iterator_name self.iterator_name = iterator_name
self.iterable = iterable self.iterable = iterable
self.requests = requests self.requests = requests
def execute(self, async=None, **context): def execute(self, _async=None, **context):
iterable = Request.expand_value_from_context(self.iterable, **context) iterable = Request.expand_value_from_context(self.iterable, **context)
response = Response() response = Response()
@ -192,7 +192,7 @@ class IfProcedure(Procedure):
context = {} context = {}
def __init__(self, name, condition, requests, else_branch=[], backend=None, id=None, **kwargs): def __init__(self, name, condition, requests, else_branch=[], backend=None, id=None, **kwargs):
kwargs['async'] = False kwargs['_async'] = False
self.condition = condition self.condition = condition
self.else_branch = [] self.else_branch = []
reqs = [] reqs = []