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
@@ -402,6 +402,12 @@ class EmojiManager:
|
||||
|
||||
logger.info("启动表情包管理器")
|
||||
|
||||
def shutdown(self) -> None:
|
||||
"""关闭EmojiManager,取消正在运行的任务"""
|
||||
if self._scan_task and not self._scan_task.done():
|
||||
self._scan_task.cancel()
|
||||
logger.info("表情包扫描任务已取消")
|
||||
|
||||
def initialize(self) -> None:
|
||||
"""初始化数据库连接和表情目录"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user