douyinWEB/scripts/_deploy_source_quota.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

92 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy split source/upload quota + auto source cover."""
import base64
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REPO = "/opt/douyinWEB"
BRANCH = "test1"
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=600):
_, o, e = c.exec_command(cmd, timeout=timeout)
out = (o.read() + e.read()).decode("utf-8", "replace").strip()
print(out[-7000:] if len(out) > 7000 else out, flush=True)
return out
def run_py(code: str, label: str):
b64 = base64.b64encode(code.encode("utf-8")).decode("ascii")
print(f"[{label}]")
return run(
f"cd {REPO}/backend && echo {b64} | base64 -d > /tmp/_src_quota.py "
f"&& PYTHONPATH=. .venv/bin/python /tmp/_src_quota.py"
)
print(
"[pull]",
run(
f"cd {REPO} && git stash push -u -m auto-src-quota || true; "
f"git fetch origin {BRANCH} && git pull --ff-only origin {BRANCH} && git log --oneline -1"
),
)
run_py(
r"""
from app import db
from app.clip_cascade import ensure_source_covers_platforms, estimate_platform_daily_need
from app import yt_long_db
from app.yt_long_pipeline import yt_long_pipeline
db.init_db()
db.update_settings_map({
'yt_long_daily_max': 42,
'yt_long_max_concurrent': 3,
'yt_long_live_sample_batch': 3,
'yt_long_source_cap': 200,
'clip_cascade_enabled': True,
'yt_long_landscape_16x9': False,
})
adj = ensure_source_covers_platforms()
print('ensure', adj)
print('need', estimate_platform_daily_need())
print('caps', {
'upload': yt_long_db.yt_long_daily_max(),
'source': yt_long_db.yt_long_source_daily_max(),
'source_used': yt_long_db.yt_long_source_used(),
'upload_used': yt_long_db.yt_long_upload_used(),
'source_gap': yt_long_db.yt_long_source_gap(),
'upload_gap': yt_long_db.yt_long_upload_gap(),
})
st = yt_long_pipeline.status()
print('status', {k: st.get(k) for k in ['enabled','running','daily_max','source_daily_max','source_used','upload_used','source_gap','upload_gap','cascade_need']})
""",
"patch",
)
run("systemctl restart douyinweb-api")
for _ in range(40):
if run("systemctl is-active douyinweb-api", timeout=15) == "active":
print("[api] active")
break
time.sleep(2)
time.sleep(4)
print("[build]", run(f"cd {REPO}/frontend && npm run build 2>&1 | tail -n 10", timeout=600))
run("systemctl restart douyinweb-web")
print("[svc]", run("systemctl is-active douyinweb-api douyinweb-web"))
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 {};"
"print('yt_long', yl.get('running'), 'up', yl.get('quota_used'), yl.get('daily_max'), 'src', yl.get('source_used'), yl.get('source_daily_max'))\""
),
)
c.close()
print("DONE")