Add SSE second-level status push for control monitor.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -32,6 +32,7 @@ async def call_node(
|
||||
*,
|
||||
require_token: bool = True,
|
||||
json_body: dict | None = None,
|
||||
timeout: float | None = None,
|
||||
) -> tuple[int, Any]:
|
||||
settings = get_control_settings()
|
||||
base = str(node["base_url"]).rstrip("/")
|
||||
@@ -43,9 +44,9 @@ async def call_node(
|
||||
headers["X-Fleet-Token"] = tok
|
||||
headers["Authorization"] = f"Fleet {tok}"
|
||||
url = f"{base}{path}"
|
||||
timeout = settings.control_http_timeout_sec
|
||||
to = float(timeout if timeout is not None else settings.control_http_timeout_sec)
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=timeout, follow_redirects=False) as client:
|
||||
async with httpx.AsyncClient(timeout=to, follow_redirects=False) as client:
|
||||
res = await client.request(method, url, headers=headers, json=json_body)
|
||||
# 少数反代会 301/302 补尾斜杠;手动跟一次并保留 Token 头
|
||||
if res.status_code in (301, 302, 307, 308) and res.headers.get("location"):
|
||||
@@ -64,12 +65,20 @@ async def call_node(
|
||||
return 502, {"detail": f"连接失败: {e}"}
|
||||
|
||||
|
||||
async def probe_health(node: dict[str, Any]) -> dict[str, Any]:
|
||||
code, data = await call_node(node, "GET", "/health", require_token=False)
|
||||
async def probe_health(
|
||||
node: dict[str, Any],
|
||||
*,
|
||||
timeout: float | None = None,
|
||||
) -> dict[str, Any]:
|
||||
code, data = await call_node(
|
||||
node, "GET", "/health", require_token=False, timeout=timeout
|
||||
)
|
||||
if code == 200 and isinstance(data, dict):
|
||||
return {"online": True, "health": data, "error": None}
|
||||
# fallback fleet status if health blocked
|
||||
code2, data2 = await call_node(node, "GET", "/api/fleet/status", require_token=True)
|
||||
code2, data2 = await call_node(
|
||||
node, "GET", "/api/fleet/status", require_token=True, timeout=timeout
|
||||
)
|
||||
if code2 == 200 and isinstance(data2, dict):
|
||||
return {"online": True, "health": data2, "error": None}
|
||||
detail = ""
|
||||
|
||||
Reference in New Issue
Block a user