Ship zombie reconcile, S3 covers, session end/drill-down, rooms ops, and refresh README for production. Co-authored-by: Cursor <cursoragent@cursor.com>
115 lines
3.5 KiB
Python
115 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy cover fix + backfill missing thumbnails."""
|
|
import json
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
HOST = "107.173.30.245"
|
|
USER = "root"
|
|
PASSWORD = "Xiao4669805"
|
|
REMOTE = "/opt/douyinWEB"
|
|
LOCAL = Path(__file__).resolve().parents[1]
|
|
FILES = [
|
|
"backend/app/douyin.py",
|
|
"backend/app/cover.py",
|
|
"backend/app/monitor.py",
|
|
"backend/app/main.py",
|
|
"backend/app/db.py",
|
|
]
|
|
|
|
|
|
def run(c, cmd: str, timeout: int = 180) -> tuple[int, str]:
|
|
print("$", cmd, 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.2)
|
|
while chan.recv_ready():
|
|
buf.append(chan.recv(65535).decode("utf-8", "replace"))
|
|
code = chan.recv_exit_status()
|
|
out = "".join(buf)
|
|
print(out[-2000:], flush=True)
|
|
return code, out
|
|
|
|
|
|
def main() -> None:
|
|
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 restart douyinweb-api --no-block; sleep 4; systemctl is-active douyinweb-api")
|
|
for i in range(20):
|
|
_, out = run(
|
|
c,
|
|
"curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health || echo fail",
|
|
timeout=30,
|
|
)
|
|
if "200" in out:
|
|
break
|
|
time.sleep(1)
|
|
|
|
# backfill can take a while (1s * N)
|
|
code, out = run(
|
|
c,
|
|
"curl -s -X POST 'http://127.0.0.1:8014/api/sessions/backfill-covers?limit=40'",
|
|
timeout=300,
|
|
)
|
|
if "{" in out:
|
|
raw = out[out.index("{") :]
|
|
try:
|
|
data = json.loads(raw)
|
|
print(
|
|
"BACKFILL",
|
|
{k: data.get(k) for k in ("ok", "fail", "attempted")},
|
|
flush=True,
|
|
)
|
|
for r in (data.get("results") or [])[:15]:
|
|
print(
|
|
" ",
|
|
r.get("anchor"),
|
|
"ok=",
|
|
r.get("ok"),
|
|
"method=",
|
|
r.get("method"),
|
|
"err=",
|
|
r.get("error"),
|
|
flush=True,
|
|
)
|
|
except Exception as exc:
|
|
print("parse err", exc, raw[:500], flush=True)
|
|
|
|
_, out = run(
|
|
c,
|
|
"/opt/douyinWEB/backend/.venv/bin/python - <<'PY'\n"
|
|
"import sqlite3\n"
|
|
"c=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')\n"
|
|
"total=c.execute('select count(*) from sessions').fetchone()[0]\n"
|
|
"empty=c.execute(\"select count(*) from sessions where cover_path is null or trim(cover_path)=''\").fetchone()[0]\n"
|
|
"print(f'total={total} no_cover={empty} with_cover={total-empty}')\n"
|
|
"for name in ['雨汐','大墨鱼']:\n"
|
|
" rows=c.execute('select anchor_name, substr(cover_path,1,70), status from sessions where anchor_name like ? order by started_at desc limit 2', (f'%{name}%',)).fetchall()\n"
|
|
" print(name, rows)\n"
|
|
"PY",
|
|
timeout=40,
|
|
)
|
|
c.close()
|
|
print("done", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|