Files

46 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 技术实现方案:19-指示灯状态自适应探测
> 迭代编号:19 依据:R-022 + R-023 | 涉及约束:产品约束-012(指示灯体系)、技术约束-016、技术约束-020/021(本迭代新增)
## 方案总览
两只连接类状态缓存统一改「**结果驱动 setTimeout 自适应链**」:每次探测完成(成功/失败/异常)后按结果排下一轮。
| 维度 | QmtHealthMonitorR-022 | QmtMcpManagerR-023 |
|---|---|---|
| 健康/已连接 | intervalMs 默认 5 分钟(稳态,原设计) | intervalMs 默认 5 分钟 |
| 异常/未知/未连接 | retryMs 默认 10 秒快速重试 | retryMs 默认 10 秒快速重试 |
| 探测目标 | 激活 baseUrl + /healthGET | 激活 baseUrl + /mcpSDK Client 握手,只读) |
| 停止调度 | stop()mounted 守卫) | 无激活连接 / dispose() / unmount() |
| 并发防护 | _inFlight 去重 | _probing 去重 |
| 前端/API | 零改动(读缓存秒回) | 零改动(getStatus 读缓存秒回) |
## 实现步骤
### R-022 QmtHealthMonitorsrc/data-source/QmtHealthMonitor.js
1. 常量 HEALTH_RETRY_MS=10s;构造注入 { intervalMs, retryMs }(测试用短间隔,对齐 QuoteSync 先例);
2. 固定 setInterval(5min) → _nextDelay()/_scheduleNext()setTimeout 链,探测完成重排);
3. resolveActiveBaseUrl 移入 try:解析失败也落 healthy:false 缓存走快速重试
(原实现解析在 try 外,抛错场景灯会灰且不自动重试——顺带修复的隐性缺陷);
4. start() 立即探测不变;stop() 用 clearTimeout + mounted 守卫。
### R-023 QmtMcpManagersrc/mcp/QmtMcpManager.js
1. 常量 PROBE_RETRY_MS=10s;构造注入 { intervalMs, retryMs }
2. probe() 结果写缓存后 _scheduleNext()target 为空早退置 disabled 并取消定时器;
3. unmount() 取消定时器;dispose() 置 _disposed + 取消 + 卸载;_probing 防并发;
4. 探测本体(SDK Client connect/initialize/tools/list)与挂载/重连逻辑零改动。
### 回归
- scripts/test-health-monitor.mjs10 项:启动即探测/异常快速重试自动恢复/健康稳态不空转/stop 停止调度…)
- scripts/test-mcp-status.mjs12 项:无激活连接不调度/异常快速重试自动恢复/已连接稳态不空转/dispose 停止调度/节奏选择;
SDK 握手不可纯内存 mock,守护调度机制:stub probe 翻转状态 + 触达真实 _scheduleNext
## 涉及文件
- src/data-source/QmtHealthMonitor.js、src/mcp/QmtMcpManager.js(核心改动)
- scripts/test-health-monitor.mjs、scripts/test-mcp-status.mjs(新增回归)
- lib/*build 再产物,部署用)