refactor(core): 统一和改进程序优雅关闭逻辑
将分散的关闭逻辑集中到`MainSystem`中,并由`bot.py`中的顶层异常处理块统一调用。这简化了关闭流程,提高了系统的健壮性和可维护性。 - 将信号处理逻辑从`MainSystem`移除,改由`bot.py`中的`try...finally`块处理,以捕获更广泛的退出场景(如`KeyboardInterrupt`)。 - `graceful_shutdown`函数现在接收`main_system`实例,直接调用其`shutdown`方法,实现了责任的单一化。 - 为`EmojiManager`和`VectorMemoryStorage`添加了`shutdown`/`cleanup`方法,确保其后台任务和资源能被正确清理。 - 调整了`MemorySystem`中对`unified_storage.cleanup()`的调用,使其与接口保持一致。
This commit is contained in:
committed by
Windpicker-owo
parent
9175207e79
commit
a273be76d3
@@ -1425,16 +1425,6 @@ class MemorySystem:
|
||||
def _fingerprint_key(user_id: str, fingerprint: str) -> str:
|
||||
return f"{user_id!s}:{fingerprint}"
|
||||
|
||||
def get_system_stats(self) -> dict[str, Any]:
|
||||
"""获取系统统计信息"""
|
||||
return {
|
||||
"status": self.status.value,
|
||||
"total_memories": self.total_memories,
|
||||
"last_build_time": self.last_build_time,
|
||||
"last_retrieval_time": self.last_retrieval_time,
|
||||
"config": asdict(self.config),
|
||||
}
|
||||
|
||||
def _compute_memory_score(self, query_text: str, memory: MemoryChunk, context: dict[str, Any]) -> float:
|
||||
"""根据查询和上下文为记忆计算匹配分数"""
|
||||
tokens_query = self._tokenize_text(query_text)
|
||||
@@ -1542,7 +1532,7 @@ class MemorySystem:
|
||||
|
||||
# 保存统一存储数据
|
||||
if self.unified_storage:
|
||||
await self.unified_storage.cleanup()
|
||||
self.unified_storage.cleanup()
|
||||
|
||||
logger.info("✅ 简化记忆系统已关闭")
|
||||
|
||||
|
||||
@@ -964,6 +964,11 @@ class VectorMemoryStorage:
|
||||
|
||||
logger.info("Vector记忆存储系统已停止")
|
||||
|
||||
def cleanup(self):
|
||||
"""清理资源,兼容旧接口"""
|
||||
logger.info("正在清理VectorMemoryStorage资源...")
|
||||
self.stop()
|
||||
|
||||
|
||||
# 全局实例(可选)
|
||||
_global_vector_storage = None
|
||||
|
||||
Reference in New Issue
Block a user