simplify publish function

This commit is contained in:
Emmanuel Garette 2020-04-23 07:39:22 +02:00
parent 9741669487
commit 664a2404fa
1 changed files with 33 additions and 36 deletions

View File

@ -147,40 +147,39 @@ class PublishDispatcher:
check_role, check_role,
kwargs, kwargs,
function_objs) function_objs)
else: try:
try: async with self.pool.acquire() as connection:
async with self.pool.acquire() as connection: await connection.set_type_codec(
await connection.set_type_codec( 'json',
'json', encoder=dumps,
encoder=dumps, decoder=loads,
decoder=loads, schema='pg_catalog'
schema='pg_catalog' )
) risotto_context.connection = connection
risotto_context.connection = connection async with connection.transaction():
async with connection.transaction(): return await self.launch(version,
return await self.launch(version, message,
message, risotto_context,
risotto_context, check_role,
check_role, kwargs,
kwargs, function_objs)
function_objs) except CallError as err:
except CallError as err: raise err
raise err except Exception as err:
except Exception as err: # if there is a problem with arguments, just send an error and do nothing
# if there is a problem with arguments, just send an error and do nothing if get_config()['global']['debug']:
if get_config()['global']['debug']: print_exc()
print_exc() async with self.pool.acquire() as connection:
async with self.pool.acquire() as connection: await connection.set_type_codec(
await connection.set_type_codec( 'json',
'json', encoder=dumps,
encoder=dumps, decoder=loads,
decoder=loads, schema='pg_catalog'
schema='pg_catalog' )
) risotto_context.connection = connection
risotto_context.connection = connection async with connection.transaction():
async with connection.transaction(): await log.error_msg(risotto_context, kwargs, err)
await log.error_msg(risotto_context, kwargs, err) raise err
raise err
class Dispatcher(register.RegisterDispatcher, class Dispatcher(register.RegisterDispatcher,
@ -329,8 +328,6 @@ class Dispatcher(register.RegisterDispatcher,
if key in function_obj['arguments']: if key in function_obj['arguments']:
kw[key] = value kw[key] = value
kw['risotto_context'] = risotto_context kw['risotto_context'] = risotto_context
returns = await function(self.injected_self[function_obj['module']], **kw) returns = await function(self.injected_self[function_obj['module']], **kw)
if risotto_context.type == 'rpc': if risotto_context.type == 'rpc':