refactor: 优化启停逻辑

This commit is contained in:
jxxghp
2025-05-13 23:47:12 +08:00
parent cf28e1d963
commit ee9c4948d3
4 changed files with 58 additions and 23 deletions

View File

@@ -4,7 +4,7 @@ from app.core.plugin import PluginManager
from app.log import logger
async def init_plugins():
async def sync_plugins() -> bool:
"""
初始化安装插件并动态注册后台任务及API
"""
@@ -18,16 +18,19 @@ async def init_plugins():
# 判断是否需要进行插件初始化
if not sync_result and not resolved_dependencies:
logger.debug("没有新的插件同步到本地或缺失依赖项需要安装")
return False
# 继续执行后续的插件初始化步骤
logger.info("正在初始化所有插件")
# 安装完成后初始化插件
plugin_manager.start()
# 插件启动后注册插件API
logger.info("正在重新初始化插件")
# 重新初始化插件
plugin_manager.init_config()
# 重新注册插件API
register_plugin_api()
logger.info("所有插件初始化完成")
return True
except Exception as e:
logger.error(f"插件初始化过程中出现异常: {e}")
return False
async def execute_task(loop, task_func, task_name):
@@ -54,6 +57,14 @@ def register_plugin_api():
plugin.register_plugin_api()
def init_plugins():
"""
初始化插件
"""
PluginManager().start()
register_plugin_api()
def stop_plugins():
"""
停止插件