Keep monitor alive across nav and speed up status collect.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -56,26 +56,39 @@ async def _collect_one_status(
|
||||
*,
|
||||
timeout: float | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""有 Token 时只打 fleet/status(含在线+持仓),避免 /health 再多一跳。"""
|
||||
base = _public_node(node)
|
||||
if not node.get("token_sealed"):
|
||||
probe = await probe_health(node, timeout=timeout)
|
||||
return {
|
||||
**base,
|
||||
**probe,
|
||||
"fleet_ok": False,
|
||||
"fleet_error": "未生成 Token",
|
||||
}
|
||||
|
||||
code, data = await call_node(
|
||||
node, "GET", "/api/fleet/status", timeout=timeout
|
||||
)
|
||||
if code == 200 and isinstance(data, dict):
|
||||
return {
|
||||
**base,
|
||||
"online": True,
|
||||
"health": None,
|
||||
"error": None,
|
||||
"from_fleet": True,
|
||||
"fleet": data,
|
||||
"fleet_ok": True,
|
||||
}
|
||||
|
||||
# fleet 失败时再探 /health,区分离线 vs Token 错误
|
||||
probe = await probe_health(node, timeout=timeout)
|
||||
item: dict[str, Any] = {**_public_node(node), **probe}
|
||||
if probe.get("online") and node.get("token_sealed"):
|
||||
# /health 也有 mode+strategy,但不能当 fleet(无持仓详情)。
|
||||
# 仅当 probe 已用 fleet 回退时复用,否则必须再拉 /api/fleet/status。
|
||||
if probe.get("from_fleet") and isinstance(probe.get("health"), dict):
|
||||
code, data = 200, probe["health"]
|
||||
else:
|
||||
code, data = await call_node(
|
||||
node, "GET", "/api/fleet/status", timeout=timeout
|
||||
)
|
||||
if code == 200 and isinstance(data, dict):
|
||||
item["fleet"] = data
|
||||
item["fleet_ok"] = True
|
||||
else:
|
||||
item["fleet_ok"] = False
|
||||
item["fleet_error"] = _http_detail(data) if data else f"HTTP {code}"
|
||||
elif not node.get("token_sealed"):
|
||||
item["fleet_ok"] = False
|
||||
item["fleet_error"] = "未生成 Token"
|
||||
item: dict[str, Any] = {
|
||||
**base,
|
||||
**probe,
|
||||
"fleet_ok": False,
|
||||
"fleet_error": _http_detail(data) if data else f"HTTP {code}",
|
||||
}
|
||||
return item
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user