douyinWEB/scripts/_fix_yt_long_running.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

45 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
def run(cmd, timeout=120):
_, o, e = c.exec_command(cmd, timeout=timeout)
out = (o.read() + e.read()).decode("utf-8", "replace").strip()
print(out[-4000:] if len(out) > 4000 else out, flush=True)
return out
print("[svc]", run("systemctl is-active douyinweb-api douyinweb-web; ss -lntp | grep -E '8787|3000|8000' | head -20"))
print("[env]", run("grep -E 'PORT|HOST|UVICORN' /etc/systemd/system/douyinweb-api.service /opt/douyinWEB/backend/.env 2>/dev/null | head -40"))
print("[start+jobs]")
print(run(r"""cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'
from app import db, yt_long_db
from app.yt_long_pipeline import yt_long_pipeline
import asyncio
db.init_db()
cfg = db.get_settings_map()
print('enabled', cfg.get('yt_long_enabled'))
# ensure running
async def go():
if not yt_long_pipeline.status().get('running'):
await yt_long_pipeline.start()
pending = yt_long_db.list_pending_yt_long_jobs(limit=20)
print('pending', len(pending), [p.get('id') for p in pending])
n = await yt_long_pipeline.kick_pending_records([str(p.get('id')) for p in pending])
print('kicked', n)
st = yt_long_pipeline.status()
print('status', {k: st.get(k) for k in ['enabled','running','busy','quota_used','quota_gap','douyin_live_count','last_error']})
jobs = yt_long_db.list_yt_long_jobs(limit=10)
for j in jobs:
print('job', j.get('id')[:8], j.get('status'), j.get('anchor_name'), j.get('error'))
asyncio.run(go())
PY"""))
# find listen port from process
print("[ports]", run("systemctl cat douyinweb-api | head -80"))
c.close()