From cf3ad1385503f2e5483dbe564a318c065398b169 Mon Sep 17 00:00:00 2001 From: noO0ob Date: Fri, 28 Jun 2024 17:44:27 +0800 Subject: [PATCH 1/3] add sqlite db reset threshold --- lyrebird/db/database_server.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lyrebird/db/database_server.py b/lyrebird/db/database_server.py index 7a3db972..77a64a85 100644 --- a/lyrebird/db/database_server.py +++ b/lyrebird/db/database_server.py @@ -34,6 +34,8 @@ class LyrebirdDatabaseServer(ThreadServer): def __init__(self, path=None): self.database_uri = None + self.error_log = [] + self.error_log_threshold = application.config.get('event.db_connection_recover_threshold', 0) super().__init__() if not path or path.isspace(): @@ -162,10 +164,15 @@ def run(self): session.add(event) session.commit() context.emit('db_action', 'add event log') - except OperationalError: + except OperationalError as e: logger.error(f'Save event failed. {traceback.format_exc()}') - logger.warning(f'DB would be reset: {self.database_uri}') - self.reset() + self.error_log.append(e) + if len(self.error_log) > self.error_log_threshold: + logger.warning(f'DB would be reset: {self.database_uri}') + self.error_log = [] + self.reset() + else: + session.rollback() except Exception: logger.error(f'Save event failed. {traceback.format_exc()}') From 910e5eb3684f4b6b5f59cb77e74853055361994b Mon Sep 17 00:00:00 2001 From: noO0ob Date: Fri, 28 Jun 2024 20:29:18 +0800 Subject: [PATCH 2/3] refresh session --- lyrebird/db/database_server.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lyrebird/db/database_server.py b/lyrebird/db/database_server.py index 77a64a85..e27f9ac7 100644 --- a/lyrebird/db/database_server.py +++ b/lyrebird/db/database_server.py @@ -171,10 +171,12 @@ def run(self): logger.warning(f'DB would be reset: {self.database_uri}') self.error_log = [] self.reset() + session = self._scoped_session() else: session.rollback() except Exception: logger.error(f'Save event failed. {traceback.format_exc()}') + session.rollback() def stop(self): super().stop() From 307f61663b09a33b650728d39bd79b92f9cfd287 Mon Sep 17 00:00:00 2001 From: noO0ob Date: Tue, 2 Jul 2024 10:01:15 +0800 Subject: [PATCH 3/3] change notice word --- lyrebird/mock/extra_mock_server/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lyrebird/mock/extra_mock_server/server.py b/lyrebird/mock/extra_mock_server/server.py index 8c3bdc0b..ff2a8410 100644 --- a/lyrebird/mock/extra_mock_server/server.py +++ b/lyrebird/mock/extra_mock_server/server.py @@ -87,7 +87,7 @@ async def send_request(context: LyrebirdProxyContext, target_url): async for data in _resp.content.iter_any(): await resp.write(data) await resp.write_eof() - logger.info(f'Stream Request finished: {proxy_resp_status} {context.origin_url}') + logger.info(f'Stream Response finished: {proxy_resp_status} {context.origin_url}') else: proxy_resp_data = await _resp.read() response_headers = await make_response_header(proxy_resp_headers, context, proxy_resp_data)