douyinWEB/scripts/_selftest_asian_status_flap.py
2026-09-13 22:10:49 -05:00

99 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Self-test: asian streetfood status stability + Studio preparing fields on dylive."""
from __future__ import annotations
import json
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
GID = "3fb8cbf7-2180-45bc-99f0-836169f0bf97"
def ssh():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
22,
"root",
"Xiao4669805",
timeout=45,
allow_agent=False,
look_for_keys=False,
banner_timeout=120,
)
return c
def run(c, cmd, t=180):
print(f"\n$ {cmd[:200]}", flush=True)
_i, o, e = c.exec_command(cmd, timeout=t)
code = o.channel.recv_exit_status()
out = (o.read() + e.read()).decode("utf-8", "replace")
print(out[-12000:] if len(out) > 12000 else out, flush=True)
return code, out
c = ssh()
code, _ = run(
c,
r"""
set -euo pipefail
cd /opt/douyinWEB/backend
./.venv/bin/python - <<'PY'
import json, time, http.cookiejar, urllib.request
GID = "3fb8cbf7-2180-45bc-99f0-836169f0bf97"
cj = http.cookiejar.CookieJar()
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
login = urllib.request.Request(
"http://127.0.0.1:8014/api/auth/login",
data=json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode(),
headers={"Content-Type": "application/json"},
method="POST",
)
with op.open(login, timeout=20) as r:
print("login", r.status, r.read()[:120])
seq = []
for i in range(6):
with op.open("http://127.0.0.1:8014/api/youtube/relay/status", timeout=20) as r:
d = json.loads(r.read().decode())
rows = d.get("groups") or d.get("relay_groups") or []
row = next((x for x in rows if str(x.get("group_id")) == GID), {})
seq.append({
"i": i,
"biz": row.get("business_status"),
"row": row.get("status"),
"push": row.get("is_pushing"),
"pid": row.get("ffmpeg_pid") or 0,
"note": (row.get("business_note") or "")[:70],
})
time.sleep(3.0)
print(json.dumps(seq, ensure_ascii=False, indent=2))
biz = [x["biz"] for x in seq]
bad = ("monitoring" in biz and "streaming" in biz and biz[-1] == "monitoring")
print("unique_biz", sorted(set(str(x) for x in biz)))
print("bad_flap_back_to_monitoring", bad)
from app import youtube_neko
sig = youtube_neko._cdp_studio_page_signals(7, force=True, max_age_sec=0.0)
print("cdp7", json.dumps({
k: sig.get(k) for k in (
"ok", "live_status", "on_air", "preparing_stream", "control_ready",
"health", "encoder_receiving",
)
}, ensure_ascii=False))
txt = str(sig.get("text") or "")[:180]
print("cdp_text", txt.replace("\n", " | "))
PY
""",
)
c.close()
raise SystemExit(code)