douyinWEB/scripts/_probe_dylive_normal_offline.py
eric c1f3bd3c57 Fix exclusive sticky when Douyin probe says offline (status=4).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-14 06:03:46 -05:00

107 lines
4.2 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
import json
import sys
import paramiko
HOST = "107.173.30.245"
PASS = "Xiao4669805"
REMOTE = r'''
cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'
import json
from app import db, yt_assign_db, youtube_relay_db
from app.youtube_relay_status import summarize_relay_group
from app.youtube_relay_pipeline import youtube_relay_pipeline as rp, _normal_auto_candidates, pick_source_for_group
cfg = db.get_settings_map()
for k in sorted(cfg):
if 'relay' in k or 'slot' in k or 'exclusive' in k:
print('CFG', k, '=', cfg[k])
groups = yt_assign_db.list_groups(include_urls=True)
normals = [g for g in groups if (g.get('category') or 'normal') == 'normal']
print('normal_groups', len(normals), 'all', len(groups))
print('exclusive_winner', getattr(rp, '_exclusive_winner', None))
print('relay_running', getattr(rp, '_running', None), getattr(rp, 'running', None))
print('rp_procs', list(getattr(rp, '_procs', {}) or {})[:10] if hasattr(rp,'_procs') else 'n/a')
# candidates
cands = _normal_auto_candidates(groups)
print('normal_auto_candidates', len(cands))
for c in cands:
print(' CAND', c.get('name'), 'gid', str(c.get('id'))[:8], 'feat', len(c.get('featured') or []))
# each normal: featured live + relay state
for g in normals:
name = g.get('name') or ''
gid = g.get('id')
feat = g.get('featured') or []
print('====', name, 'gid', str(gid)[:8], 'neko', g.get('neko_instance_id'), 'neko_en', g.get('neko_enabled'), 'feat_n', len(feat))
for f in feat[:8]:
print(' FEAT', f.get('room_id') or '', (f.get('title') or '')[:40], (f.get('url') or '')[:60])
try:
src = pick_source_for_group(g, respect_schedule=False)
print(' PICK_SRC', json.dumps(src, ensure_ascii=False, default=str)[:300] if src else None)
except Exception as e:
print(' PICK_ERR', e)
st = youtube_relay_db.get_relay_state(gid) or {}
print(' STATE', json.dumps({k: st.get(k) for k in ('status','error','source_url','source_room_id','pid','started_at','updated_at','manual_hold','ffmpeg_running','is_pushing')}, ensure_ascii=False, default=str)[:500])
# ffmpeg processes for this group
try:
summ = summarize_relay_group(g, st)
print(' SUM', json.dumps({k: summ.get(k) for k in ('business_status','is_pushing','status_label','error','source_room_id','neko')}, ensure_ascii=False, default=str)[:400])
except Exception as e:
print(' SUM_ERR', e)
# live rooms from monitor matching featured
live_rids=set()
try:
rows = db.list_rooms(limit=500) if hasattr(db,'list_rooms') else None
except Exception:
rows=None
if rows is None:
import sqlite3
from app.config import settings
path = getattr(settings, 'db_path', None) or '/opt/douyinWEB/backend/data/monitor.db'
con=sqlite3.connect(path); con.row_factory=sqlite3.Row
cols=[r[1] for r in con.execute('PRAGMA table_info(rooms)')]
print('rooms_cols', cols[:25])
q="SELECT room_id, last_anchor, last_status FROM rooms WHERE COALESCE(last_status,'')='live' LIMIT 30"
try:
rs=con.execute(q).fetchall()
except Exception as e:
print('qerr', e)
# try simpler
rs=con.execute('SELECT room_id, last_status FROM rooms LIMIT 5').fetchall()
print('sample', [dict(r) for r in rs])
rs=[]
for r in rs:
live_rids.add(str(r['room_id']))
print('LIVE_ROOM', r['room_id'], (r['last_anchor'] if 'last_anchor' in r.keys() else ''), r['last_status'] if 'last_status' in r.keys() else '')
else:
print('list_rooms', type(rows))
print('LIVE_RIDS', sorted(live_rids)[:20])
# ffmpeg / docker neko
import subprocess
print('FFMPEG', subprocess.getoutput('ps -ef | grep -E \"ffmpeg.*youtube|ffmpeg.*rtmp\" | grep -v grep | head -20')[:800])
print('NEKO', subprocess.getoutput('docker ps --format \"{{.Names}} {{.Status}}\" | grep -E \"douyinweb-neko\" | head -20')[:800])
PY
'''
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, "root", PASS, timeout=40, allow_agent=False, look_for_keys=False)
_, o, e = c.exec_command(REMOTE, timeout=90)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
if __name__ == "__main__":
main()