Add control monitor Start All for stopped fleet nodes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-02 14:52:56 +08:00
parent 4059d826e1
commit 92c2e89b0e
2 changed files with 99 additions and 0 deletions
+39
View File
@@ -222,6 +222,45 @@ async def update_batch(
return {"results": results}
@router.post("/start-batch")
async def start_batch(
body: dict,
_user: Annotated[str, Depends(require_control_user)],
) -> dict:
"""并行启动多台策略机(Fleet start)。"""
ids = body.get("ids") or []
if not isinstance(ids, list) or not ids:
raise HTTPException(status_code=400, detail="ids 不能为空")
db = get_control_db()
async def _one(nid: int) -> dict:
node = db.get_node(int(nid))
if not node:
return {"id": nid, "ok": False, "detail": "不存在", "name": str(nid)}
name = str(node.get("name") or nid)
if not node.get("token_sealed"):
return {"id": nid, "ok": False, "detail": "未生成 Token", "name": name}
try:
code, data = await call_node(node, "POST", "/api/fleet/start", timeout=20.0)
except Exception as ex:
return {"id": nid, "ok": False, "detail": str(ex), "name": name}
detail = ""
if code >= 400:
detail = _http_detail(data) if data else f"HTTP {code}"
return {
"id": nid,
"name": name,
"ok": code < 400,
"status": code,
"detail": detail,
"result": data,
}
items = list(await asyncio.gather(*[_one(int(x)) for x in ids]))
ok_n = sum(1 for x in items if x.get("ok"))
return {"ok": ok_n == len(items), "started": ok_n, "total": len(items), "results": items}
@router.patch("/{node_id}")
async def update_node(
node_id: int,