# -*- coding: utf-8 -*- """Finish FE build + pull-forward parked Shorts slots (venv-aware).""" from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") SCRIPT = r'''#!/bin/bash set -euo pipefail cd /opt/douyinWEB if [ -f .venv/bin/activate ]; then . .venv/bin/activate; fi if [ -f venv/bin/activate ]; then . venv/bin/activate; fi if [ -f backend/.venv/bin/activate ]; then . backend/.venv/bin/activate; fi echo "python=$(command -v python || true)" python -c "import pydantic_settings; print('pydantic_ok')" cd /opt/douyinWEB/backend python <<'PY' import sys, sqlite3, time, datetime sys.path.insert(0, "/opt/douyinWEB/backend") from app.shorts_schedule import fleet_pace_plan, pull_forward_due_uploads plan = fleet_pace_plan() keys = ( "uploaded", "front_target", "need_front", "behind", "urgent", "recommended_global_gap_sec", "recommended_channel_gap_sec", "recommended_per_hour", ) print("pace", {k: plan.get(k) for k in keys}) print("pulled", pull_forward_due_uploads()) BJ = datetime.timezone(datetime.timedelta(hours=8)) now = time.time() day = datetime.datetime.now(BJ).strftime("%Y-%m-%d") con = sqlite3.connect("/opt/douyinWEB/backend/data/monitor.db") due = fut = 0 hours = {} q = ( "SELECT upload_at FROM shorts_jobs WHERE push_date=? " "AND status IN ('scheduled','recorded') AND IFNULL(clip_path,'')!=''" ) for (ua0,) in con.execute(q, (day,)): ua = float(ua0 or 0) if ua <= now + 90: due += 1 else: fut += 1 if ua > 0: h = datetime.datetime.fromtimestamp(ua, BJ).hour hours[h] = hours.get(h, 0) + 1 print("due_now", due, "future", fut, "by_hour", dict(sorted(hours.items()))) con.close() PY cd /opt/douyinWEB/frontend npm run build 2>&1 | tail -20 systemctl restart douyinweb-web.service sleep 3 systemctl is-active douyinweb-web.service ''' def run(label: str, host: str, port: int, user: str, pw: str, *, sudo: bool) -> None: print(f"\n===== {label} =====") c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(host, port, user, pw, timeout=45, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() with sftp.file("/tmp/_dy_pace_finish.sh", "w") as f: f.write(SCRIPT.replace("\r\n", "\n")) sftp.close() cmd = ( f"echo '{pw}' | sudo -S -p '' bash /tmp/_dy_pace_finish.sh" if sudo else "bash /tmp/_dy_pace_finish.sh" ) _, o, e = c.exec_command(cmd, timeout=600) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() run("vps-dylive", "107.173.30.245", 22, "root", "Xiao4669805", sudo=False) run("phys-dy", "107.173.30.245", 4014, "eric", "4669805", sudo=True) print("DONE")