From 7098c8755f0375314550318617af9884dd43d498 Mon Sep 17 00:00:00 2001 From: snaily Date: Sat, 26 Apr 2025 03:27:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=94=B9=E8=BF=9B=E8=B0=83?= =?UTF-8?q?=E5=BA=A6=E5=99=A8=E5=90=AF=E5=8A=A8=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E6=B8=85=E7=90=86=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 `key_checker.py` 中的调度器启动逻辑,确保即使实例存在但未运行时也能启动。 - 在 `key_checker.py` 中添加了调度器启动和状态日志。 - 移除了 `application.py` 中数据库断开连接和调度器停止时的冗余关闭日志。 --- app/core/application.py | 2 -- app/scheduler/key_checker.py | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/core/application.py b/app/core/application.py index a36cc4c..8057508 100644 --- a/app/core/application.py +++ b/app/core/application.py @@ -54,7 +54,6 @@ async def _setup_database_and_config(app_settings): async def _shutdown_database(): """Disconnects from the database.""" await disconnect_from_db() - logger.info("Disconnected from database.") def _start_scheduler(): """Starts the background scheduler.""" @@ -67,7 +66,6 @@ def _start_scheduler(): def _stop_scheduler(): """Stops the background scheduler.""" stop_scheduler() - logger.info("Scheduler stopped.") async def _perform_update_check(app: FastAPI): """Checks for updates and stores the info in app.state.""" diff --git a/app/scheduler/key_checker.py b/app/scheduler/key_checker.py index 4dd0b0d..ed58e13 100644 --- a/app/scheduler/key_checker.py +++ b/app/scheduler/key_checker.py @@ -90,8 +90,10 @@ scheduler_instance = None def start_scheduler(): global scheduler_instance - if scheduler_instance is None: + if scheduler_instance is None or not scheduler_instance.running: + logger.info("Starting scheduler...") scheduler_instance = setup_scheduler() + logger.info("Scheduler is already running.") def stop_scheduler(): global scheduler_instance