mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-09-08 09:26:36 +08:00
refactor: 改进调度器启动逻辑并清理日志
- 修改 `key_checker.py` 中的调度器启动逻辑,确保即使实例存在但未运行时也能启动。 - 在 `key_checker.py` 中添加了调度器启动和状态日志。 - 移除了 `application.py` 中数据库断开连接和调度器停止时的冗余关闭日志。
This commit is contained in:
@@ -54,7 +54,6 @@ async def _setup_database_and_config(app_settings):
|
|||||||
async def _shutdown_database():
|
async def _shutdown_database():
|
||||||
"""Disconnects from the database."""
|
"""Disconnects from the database."""
|
||||||
await disconnect_from_db()
|
await disconnect_from_db()
|
||||||
logger.info("Disconnected from database.")
|
|
||||||
|
|
||||||
def _start_scheduler():
|
def _start_scheduler():
|
||||||
"""Starts the background scheduler."""
|
"""Starts the background scheduler."""
|
||||||
@@ -67,7 +66,6 @@ def _start_scheduler():
|
|||||||
def _stop_scheduler():
|
def _stop_scheduler():
|
||||||
"""Stops the background scheduler."""
|
"""Stops the background scheduler."""
|
||||||
stop_scheduler()
|
stop_scheduler()
|
||||||
logger.info("Scheduler stopped.")
|
|
||||||
|
|
||||||
async def _perform_update_check(app: FastAPI):
|
async def _perform_update_check(app: FastAPI):
|
||||||
"""Checks for updates and stores the info in app.state."""
|
"""Checks for updates and stores the info in app.state."""
|
||||||
|
|||||||
@@ -90,8 +90,10 @@ scheduler_instance = None
|
|||||||
|
|
||||||
def start_scheduler():
|
def start_scheduler():
|
||||||
global scheduler_instance
|
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()
|
scheduler_instance = setup_scheduler()
|
||||||
|
logger.info("Scheduler is already running.")
|
||||||
|
|
||||||
def stop_scheduler():
|
def stop_scheduler():
|
||||||
global scheduler_instance
|
global scheduler_instance
|
||||||
|
|||||||
Reference in New Issue
Block a user