# -*- coding: utf-8 -*- import sys 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[-6000:] if len(out) > 6000 else out, flush=True) return out py = r''' from app import db, yt_long_db from collections import Counter import time db.init_db() # clear weak global templates so SEO pool wins m = db.get_settings_map() tpl = str(m.get("yt_long_title_template") or "").strip().lower() dtpl = str(m.get("yt_long_description_template") or "").strip().lower() patch = {} if tpl and ("street food" in tpl or tpl in ("{anchor}", "{anchor} street food live")): patch["yt_long_title_template"] = "" if dtpl and ("{anchor}" in dtpl or "#shorts" in dtpl): patch["yt_long_description_template"] = "" if patch: db.update_settings_map(patch) print("cleared", patch) else: print("templates ok", repr(m.get("yt_long_title_template")), repr(m.get("yt_long_description_template"))) # skip leftover pending/scheduled if inflight already fills daily max from app.timeutil import push_date_from_ts day = push_date_from_ts(time.time()) dmax = yt_long_db.yt_long_daily_max() inflight = sum(yt_long_db.count_yt_long_jobs_by_status(s, push_date=day) for s in ("recording","recorded","scheduled","uploading","uploaded")) print("day", day, "dmax", dmax, "inflight", inflight) skipped = 0 if dmax > 0 and inflight >= dmax: for j in yt_long_db.list_yt_long_jobs(limit=50): if j.get("push_date") != day: continue if j.get("status") in ("pending",): yt_long_db.update_yt_long_job(str(j["id"]), status="skipped", error="daily_quota_full", finished_at=time.time()) skipped += 1 print("skipped_pending", skipped) jobs = yt_long_db.list_yt_long_jobs(limit=40) print("jobs", dict(Counter(j.get("status") for j in jobs))) print("quota", yt_long_db.yt_long_quota_used(day), "/", dmax, "gap", yt_long_db.yt_long_quota_gap(day)) ''' sftp = c.open_sftp() with sftp.file("/tmp/yt_long_finish.py", "w") as f: f.write(py) sftp.close() print(run("cd /opt/douyinWEB/backend && PYTHONPATH=. .venv/bin/python /tmp/yt_long_finish.py")) print("[svc]", run("systemctl is-active douyinweb-api douyinweb-web; cd /opt/douyinWEB && git log --oneline -1")) print("[health]", run("curl -sS -m 15 http://127.0.0.1:8014/api/health | python3 -c \"import sys,json;h=json.load(sys.stdin); yl=h.get('yt_long') or {}; sh=h.get('shorts') or {}; mo=h.get('monitor') or {}; print('api_ok', h.get('ok')); print('yt_long', yl.get('enabled'), yl.get('running'), yl.get('quota_used'), yl.get('quota_gap')); print('shorts', sh.get('enabled'), sh.get('running'), sh.get('quota_gap')); print('monitor', mo.get('running'), mo.get('live_count'), (mo.get('overdue') or {}).get('count'))\"")) c.close()