refactor: 改进调度器启动逻辑并清理日志

- 修改 `key_checker.py` 中的调度器启动逻辑,确保即使实例存在但未运行时也能启动。
- 在 `key_checker.py` 中添加了调度器启动和状态日志。
- 移除了 `application.py` 中数据库断开连接和调度器停止时的冗余关闭日志。
This commit is contained in:
snaily
2025-04-26 03:27:13 +08:00
parent 705d602dee
commit 7098c8755f
2 changed files with 3 additions and 3 deletions

View File

@@ -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."""

View File

@@ -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