better debug messages
This commit is contained in:
parent
d6bbcaa65c
commit
db8bdf4a6d
|
@ -20,7 +20,7 @@ class Controller:
|
|||
version, module, message = uri.split('.', 2)
|
||||
uri = module + '.' + message
|
||||
if module not in self.risotto_modules:
|
||||
return await remote.call_or_publish(module,
|
||||
return await remote.remove_call(module,
|
||||
version,
|
||||
message,
|
||||
kwargs)
|
||||
|
@ -37,10 +37,11 @@ class Controller:
|
|||
version, module, submessage = uri.split('.', 2)
|
||||
version, message = uri.split('.', 1)
|
||||
if module not in self.risotto_modules:
|
||||
await remote.call_or_publish(module,
|
||||
await remote.remove_call(module,
|
||||
version,
|
||||
submessage,
|
||||
kwargs)
|
||||
else:
|
||||
await dispatcher.publish(version,
|
||||
message,
|
||||
risotto_context,
|
||||
|
|
|
@ -134,7 +134,10 @@ class PublishDispatcher:
|
|||
version,
|
||||
message,
|
||||
'event')
|
||||
try:
|
||||
function_objs = self.messages[version][message].get('functions', [])
|
||||
except KeyError:
|
||||
raise ValueError(_(f'cannot find message {version}.{message}'))
|
||||
# do not start a new database connection
|
||||
if hasattr(old_risotto_context, 'connection'):
|
||||
risotto_context.connection = old_risotto_context.connection
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
from typing import Dict, Any
|
||||
from json import dumps
|
||||
from asyncpg.exceptions import UndefinedTableError
|
||||
|
||||
|
||||
from .context import Context
|
||||
from .utils import _
|
||||
from .config import get_config
|
||||
|
@ -23,7 +26,10 @@ class Logger:
|
|||
args.append(dumps(data))
|
||||
|
||||
sql = insert + ') ' + values + ')'
|
||||
try:
|
||||
await risotto_context.connection.fetch(sql, *args)
|
||||
except UndefinedTableError as err:
|
||||
raise Exception(_(f'cannot access to database ({err}), was the database really created?'))
|
||||
|
||||
def _get_message_paths(self,
|
||||
risotto_context: Context):
|
||||
|
|
|
@ -5,18 +5,19 @@ from tiramisu_api import Config
|
|||
|
||||
|
||||
from .config import get_config
|
||||
from .utils import _
|
||||
#
|
||||
#
|
||||
# ALLOW_INSECURE_HTTPS = get_config()['submodule']['allow_insecure_https']
|
||||
# ALLOW_INSECURE_HTTPS = get_config()['module']['allow_insecure_https']
|
||||
|
||||
|
||||
class Remote:
|
||||
submodules = {}
|
||||
|
||||
async def _get_config(self,
|
||||
submodule: str,
|
||||
module: str,
|
||||
url: str) -> None:
|
||||
if submodule not in self.submodules:
|
||||
if module not in self.submodules:
|
||||
session = ClientSession()
|
||||
async with session.get(url) as resp:
|
||||
if resp.status != 200:
|
||||
|
@ -27,22 +28,25 @@ class Remote:
|
|||
err = await resp.text()
|
||||
raise Exception(err)
|
||||
json = await resp.json()
|
||||
self.submodules[submodule] = json
|
||||
return Config(self.submodules[submodule])
|
||||
self.submodules[module] = json
|
||||
return Config(self.submodules[module])
|
||||
|
||||
async def remove_call(self,
|
||||
submodule: str,
|
||||
module: str,
|
||||
version: str,
|
||||
message: str,
|
||||
submessage: str,
|
||||
payload) -> dict:
|
||||
domain_name = get_config()['submodule'][submodule]
|
||||
try:
|
||||
domain_name = get_config()['module'][module]
|
||||
except KeyError:
|
||||
raise ValueError(_(f'cannot find information of remote module "{module}" to access to "{version}.{module}.{submessage}"'))
|
||||
remote_url = f'http://{domain_name}:8080/api/{version}'
|
||||
message_url = f'{remote_url}/{message}'
|
||||
message_url = f'{remote_url}/{submessage}'
|
||||
|
||||
config = await self._get_config(submodule,
|
||||
config = await self._get_config(module,
|
||||
remote_url)
|
||||
for key, value in payload.items():
|
||||
path = message + '.' + key
|
||||
path = submessage + '.' + key
|
||||
config.option(path).value.set(value)
|
||||
session = ClientSession()
|
||||
async with session.post(message_url, data=dumps(payload)) as resp:
|
||||
|
|
Loading…
Reference in New Issue