From 7bcc1bdafd62b14d3c7ad434a471442733f9d42d Mon Sep 17 00:00:00 2001 From: VisualDust Date: Fri, 24 Nov 2023 21:35:44 +0800 Subject: [PATCH] fixed logger style varies for same identity --- neetbox/daemon/client/_connection.py | 5 ++--- neetbox/daemon/readme.md | 7 +++++++ neetbox/integrations/engine.py | 3 ++- neetbox/logging/logger.py | 7 ++++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/neetbox/daemon/client/_connection.py b/neetbox/daemon/client/_connection.py index c175ab43..42c22211 100644 --- a/neetbox/daemon/client/_connection.py +++ b/neetbox/daemon/client/_connection.py @@ -69,10 +69,9 @@ def _init_ws(): # ws server url ClientConn.ws_server_addr = f"ws://{cfg['host']}:{cfg['port'] + 1}{CLIENT_API_ROOT}" - # todo wait for server online # create websocket app logger.log(f"creating websocket connection to {ClientConn.ws_server_addr}") - # todo does run_forever reconnect after close? + ws = websocket.WebSocketApp( ClientConn.ws_server_addr, on_open=ClientConn.__on_ws_open, @@ -148,7 +147,7 @@ def ws_send(event_type: str, payload): NAME_NAME_KEY: ClientConn._display_name, EVENT_TYPE_NAME_KEY: event_type, PAYLOAD_NAME_KEY: payload, - EVENT_ID_NAME_KEY: -1, # todo + EVENT_ID_NAME_KEY: -1, # todo how does ack work } ) ) diff --git a/neetbox/daemon/readme.md b/neetbox/daemon/readme.md index 4732fe5c..d977b70e 100644 --- a/neetbox/daemon/readme.md +++ b/neetbox/daemon/readme.md @@ -1,5 +1,12 @@ # DAEMON readme +## How to run server only + +at neetbox project root: +```bash +python neetbox/daemon/server/_server.py +``` + ## WS message standard websocke messages are described in json. There is a dataclass representing websocket message: diff --git a/neetbox/integrations/engine.py b/neetbox/integrations/engine.py index fd17b903..87330f9d 100644 --- a/neetbox/integrations/engine.py +++ b/neetbox/integrations/engine.py @@ -6,6 +6,7 @@ import importlib from enum import Enum +from functools import lru_cache from typing import List, Optional from neetbox.logging import logger @@ -22,7 +23,7 @@ def __str__(self) -> str: installed_engines: Optional[List] = None -# todo migrate to python 3.9 after frameworks are supporting it +@lru_cache def get_supported_engines(): global supported_engines if not supported_engines: diff --git a/neetbox/logging/logger.py b/neetbox/logging/logger.py index feace927..92faae4c 100644 --- a/neetbox/logging/logger.py +++ b/neetbox/logging/logger.py @@ -98,11 +98,12 @@ def log( _style = self.style if not _style: # if style not set - if _caller_identity in Logger.__WHOM_2_STYLE: # check for previous style - _style = Logger.__WHOM_2_STYLE[_caller_identity] + _style_index = str(_caller_identity) + if _style_index in Logger.__WHOM_2_STYLE: # check for previous style + _style = Logger.__WHOM_2_STYLE[_style_index] else: _style = LogStyle().randcolor() - Logger.__WHOM_2_STYLE[_caller_identity] = _style + Logger.__WHOM_2_STYLE[_style_index] = _style raw_log = RawLog( rich_msg=_pure_str_message,