9cd81a3ea7
Split vn.py into qihuo-ctp worker with IPC client bridge, keep CTP connected during breaks with cached account fallback, speed up strategy page loads, and allow off-session breakout roll submissions. Co-authored-by: Cursor <cursoragent@cursor.com>
113 lines
3.1 KiB
Python
113 lines
3.1 KiB
Python
"""Verify qihuo web process survives an isolated qihuo-ctp restart."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def _connect() -> paramiko.SSHClient:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("192.168.8.21", username="root", password="woaini88", timeout=15)
|
|
return c
|
|
|
|
|
|
def _run(c: paramiko.SSHClient, cmd: str, timeout: int = 60) -> str:
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
out = o.read().decode("utf-8", "replace")
|
|
err = e.read().decode("utf-8", "replace")
|
|
return out + (("\nERR:\n" + err) if err.strip() else "")
|
|
|
|
|
|
def _pm2(c: paramiko.SSHClient) -> dict[str, dict]:
|
|
raw = _run(c, "pm2 jlist", timeout=30)
|
|
rows = json.loads(raw)
|
|
return {r.get("name"): r for r in rows}
|
|
|
|
|
|
def _restart_count(row: dict) -> int:
|
|
env = row.get("pm2_env") or {}
|
|
return int(env.get("restart_time") or 0)
|
|
|
|
|
|
def main() -> int:
|
|
c = _connect()
|
|
try:
|
|
before = _pm2(c)
|
|
for name in ("qihuo", "qihuo-ctp"):
|
|
row = before.get(name) or {}
|
|
env = row.get("pm2_env") or {}
|
|
print(
|
|
"before",
|
|
name,
|
|
"status",
|
|
env.get("status"),
|
|
"restarts",
|
|
_restart_count(row),
|
|
"pid",
|
|
row.get("pid"),
|
|
)
|
|
|
|
health = _run(
|
|
c,
|
|
'curl -s -H "X-Qihuo-CTP-Token: qihuo-local-ctp" '
|
|
"http://127.0.0.1:6601/health",
|
|
timeout=30,
|
|
)
|
|
print("worker_health", health[:1000])
|
|
web = _run(
|
|
c,
|
|
"curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:6600/login",
|
|
timeout=30,
|
|
)
|
|
print("web_login_before", web.strip())
|
|
|
|
print("restarting qihuo-ctp only")
|
|
print(_run(c, "pm2 restart qihuo-ctp --update-env", timeout=60))
|
|
time.sleep(8)
|
|
|
|
after = _pm2(c)
|
|
for name in ("qihuo", "qihuo-ctp"):
|
|
row = after.get(name) or {}
|
|
env = row.get("pm2_env") or {}
|
|
print(
|
|
"after",
|
|
name,
|
|
"status",
|
|
env.get("status"),
|
|
"restarts",
|
|
_restart_count(row),
|
|
"pid",
|
|
row.get("pid"),
|
|
)
|
|
|
|
web_after = _run(
|
|
c,
|
|
"curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:6600/login",
|
|
timeout=30,
|
|
)
|
|
print("web_login_after", web_after.strip())
|
|
|
|
qihuo_before = _restart_count(before.get("qihuo") or {})
|
|
qihuo_after = _restart_count(after.get("qihuo") or {})
|
|
ctp_before = _restart_count(before.get("qihuo-ctp") or {})
|
|
ctp_after = _restart_count(after.get("qihuo-ctp") or {})
|
|
ok = (
|
|
qihuo_after == qihuo_before
|
|
and ctp_after >= ctp_before + 1
|
|
and web_after.strip() == "200"
|
|
)
|
|
print("isolation_ok", ok)
|
|
return 0 if ok else 1
|
|
finally:
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|