fix: 插件加载失败计入统计 — LOAD_FAILURES + 合并fail_details

This commit is contained in:
qinglong
2026-06-14 10:26:36 +08:00
parent 00c97e4af2
commit 7fe9e4f6cd
2 changed files with 14 additions and 4 deletions
+4
View File
@@ -17,6 +17,9 @@ from sdk.plugin_command_decorator import plugin_command, command
logger = logging.getLogger(__name__)
# 加载失败记录 — 供统计 API 使用
LOAD_FAILURES: Dict[str, str] = {}
@dataclass
class PluginInfo:
"""插件信息数据类"""
@@ -309,6 +312,7 @@ class PluginService:
plugin_path = self.plugins_dir / plugin_name
if not plugin_path.exists():
LOAD_FAILURES[plugin_name] = "插件目录不存在"
logger.error(f"插件目录不存在: {plugin_path}")
return False
+10 -4
View File
@@ -57,19 +57,25 @@ async def plugin_stats(req):
total = len(ps.plugin_info) if ps else 0
loaded = sum(1 for n, info in ps.plugin_info.items() if n in ps.plugins) if ps else 0
disabled = total - loaded
# 启动失败: 插件目录存在但未成功加载 + 导入失败记录
# 合并: 导入失败 + 加载失败
from services.plugin_service import LOAD_FAILURES
failed = len(_IMPORT_FAILS)
fail_details = dict(_IMPORT_FAILS)
for name, reason in LOAD_FAILURES.items():
if name not in fail_details:
fail_details[name] = reason
failed += 1
if ps:
for name, info in ps.plugin_info.items():
if getattr(info, "error_count", 0) > 0 and name not in _IMPORT_FAILS:
if getattr(info, "error_count", 0) > 0 and name not in fail_details:
fail_details[name] = f"启动失败 (错误数: {info.error_count})"
failed += 1
_IMPORT_FAILS[name] = f"启动失败 (错误数: {info.error_count})"
return web.json_response({
"total": total,
"loaded": loaded,
"disabled": max(0, disabled),
"failed": failed,
"fail_details": dict(_IMPORT_FAILS),
"fail_details": fail_details,
})