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