douyinWEB/scripts/deploy_channel_cascade.py
eric 01c6bf4507 Shorts: SOCKS 代理、OAuth Client 分桶配额、频道级联清理;更新 README
取消本地上传拦截,按 A/B/C/D Client 独立展示配额;新增 SOCKS5 上传代理与删频道级联清理;同步文档与部署脚本。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-14 09:58:04 -05:00

78 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy channel-cascade delete + purge orphan shorts jobs."""
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "107.173.30.245"
USER = "root"
PASSWORD = "Xiao4669805"
REMOTE = "/opt/douyinWEB"
LOCAL = Path(__file__).resolve().parents[1]
FILES = [
"backend/app/db.py",
"backend/app/main.py",
"backend/app/shorts_pipeline.py",
"backend/app/shorts_schedule.py",
"frontend/src/app/shorts/page.tsx",
]
def run(c, cmd, timeout=420):
print("$", cmd[:200], flush=True)
chan = c.get_transport().open_session()
chan.settimeout(timeout)
chan.get_pty()
chan.exec_command(cmd)
buf = []
while True:
if chan.recv_ready():
buf.append(chan.recv(65535).decode("utf-8", "replace"))
if chan.exit_status_ready() and not chan.recv_ready():
break
time.sleep(0.25)
while chan.recv_ready():
buf.append(chan.recv(65535).decode("utf-8", "replace"))
code = chan.recv_exit_status()
text = "".join(buf)
clean = "".join(ch for ch in text if ord(ch) < 128 or "\u4e00" <= ch <= "\u9fff")
print(clean[-3000:], flush=True)
return code
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
for rel in FILES:
print("upload", rel, flush=True)
sftp.put(str(LOCAL / rel), f"{REMOTE}/{rel}")
sftp.close()
run(
c,
"systemctl kill -s SIGKILL douyinweb-api || true; sleep 1; "
"systemctl reset-failed douyinweb-api || true; "
"systemctl start douyinweb-api; sleep 5; systemctl is-active douyinweb-api",
)
run(
c,
"cd /opt/douyinWEB/backend && .venv/bin/python -c "
"\"from app import db; db.init_db(); r=db.purge_orphan_shorts_jobs(limit=2000); print('purged', r)\"",
timeout=120,
)
if run(c, "cd /opt/douyinWEB/frontend && npm run build", timeout=600) != 0:
raise SystemExit(1)
run(c, "systemctl restart douyinweb-web --no-block; sleep 4; systemctl is-active douyinweb-api douyinweb-web")
c.close()
print("DONE")
if __name__ == "__main__":
main()