fix(core): 优化应用关闭流程,确保数据库最后关闭

将数据库服务的停止操作移至所有清理任务执行完毕后,以防止其他组件在关闭时因无法访问数据库而产生异常。

此外,为数据库关闭操作增加了超时处理,增强了系统关闭时的健壮性。

- chore(config): 将模板配置文件中的默认模型由 DeepSeek-V3.1 全面升级至 DeepSeek-V3.2-Exp,以提升默认性能。
This commit is contained in:
tt-P607
2025-11-01 19:00:59 +08:00
committed by Windpicker-owo
parent ef460f5c74
commit 1857754bbe
2 changed files with 27 additions and 23 deletions

View File

@@ -218,14 +218,6 @@ class MainSystem:
cleanup_tasks = []
# 停止数据库服务
try:
from src.common.database.core import close_engine as stop_database
cleanup_tasks.append(("数据库服务", stop_database()))
except Exception as e:
logger.error(f"准备停止数据库服务时出错: {e}")
# 停止消息批处理器
try:
from src.chat.message_receive.storage import get_message_storage_batcher, get_message_update_batcher
@@ -329,6 +321,18 @@ class MainSystem:
else:
logger.warning("没有需要清理的任务")
# 停止数据库服务 (在所有其他任务完成后最后停止)
try:
from src.common.database.core import close_engine as stop_database
logger.info("正在停止数据库服务...")
await asyncio.wait_for(stop_database(), timeout=15.0)
logger.info("🛑 数据库服务已停止")
except asyncio.TimeoutError:
logger.error("停止数据库服务超时")
except Exception as e:
logger.error(f"停止数据库服务时出错: {e}")
def _cleanup(self) -> None:
"""同步清理资源(向后兼容)"""
try: