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>
103 lines
3.4 KiB
Python
103 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy 9:16 yt-long + cascade + 48h retention."""
|
|
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/_cascade_patch.py "
|
|
f"&& PYTHONPATH=. .venv/bin/python /tmp/_cascade_patch.py"
|
|
)
|
|
|
|
|
|
PATCH = r"""
|
|
from app import db
|
|
from app.clip_cascade import estimate_platform_daily_need
|
|
from app.clip_retention import purge_stale_clips
|
|
from app.yt_long_pipeline import yt_long_pipeline
|
|
|
|
db.init_db()
|
|
patch = {
|
|
'yt_long_landscape_16x9': False,
|
|
'clip_cascade_enabled': True,
|
|
'clips_max_age_hours': 48,
|
|
'yt_long_delete_clip_after_upload': False,
|
|
'shorts_delete_clip_after_upload': False,
|
|
'tiktok_delete_clip_after_upload': False,
|
|
'x_clips_delete_clip_after_post': False,
|
|
'tiktok_clip_sec': 75,
|
|
'x_clips_clip_sec': 18,
|
|
'shorts_clip_sec': 15,
|
|
}
|
|
db.update_settings_map(patch)
|
|
need = estimate_platform_daily_need()
|
|
print('settings_ok', {k: db.get_settings_map().get(k) for k in patch})
|
|
print('cascade_need', need)
|
|
st = yt_long_pipeline.status()
|
|
print('yt_long', {k: st.get(k) for k in ['enabled','running','daily_max','quota_used','quota_gap']})
|
|
print('cascade_need_status', st.get('cascade_need'))
|
|
print('landscape', st.get('settings',{}).get('yt_long_landscape_16x9'))
|
|
print('retention', purge_stale_clips())
|
|
"""
|
|
|
|
print(
|
|
"[pull]",
|
|
run(
|
|
f"cd {REPO} && git stash push -u -m auto-cascade || true; "
|
|
f"git fetch origin {BRANCH} && git pull --ff-only origin {BRANCH} && git log --oneline -1"
|
|
),
|
|
)
|
|
run_py(PATCH, "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)
|
|
run_py(
|
|
r"""
|
|
from app.yt_long_pipeline import yt_long_pipeline
|
|
from app import db
|
|
from app.yt_long_clip import _vf_for_settings
|
|
st = yt_long_pipeline.status()
|
|
print('vf', _vf_for_settings())
|
|
print('status', {k: st.get(k) for k in ['enabled','running','daily_max','cascade_need']})
|
|
print('settings', {k: st.get('settings',{}).get(k) for k in ['yt_long_landscape_16x9','clip_cascade_enabled','clips_max_age_hours','yt_long_delete_clip_after_upload']})
|
|
""",
|
|
"verify",
|
|
)
|
|
print("[build]", run(f"cd {REPO}/frontend && npm run build 2>&1 | tail -n 12", 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'), yl.get('daily_max'), yl.get('quota_used'), yl.get('quota_gap'))\""
|
|
),
|
|
)
|
|
c.close()
|
|
print("DONE")
|