95 lines
3.6 KiB
Python
95 lines
3.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy Shorts 20:00/90% front-load pacing + pull-forward parked slots."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(r"c:\Users\admin\Desktop\douyinWEB")
|
|
FILES = [
|
|
("backend/app/shorts_schedule.py", "/tmp/_dy_shorts_schedule.py"),
|
|
("backend/app/shorts_pipeline.py", "/tmp/_dy_shorts_pipeline.py"),
|
|
("frontend/src/app/shorts/page.tsx", "/tmp/_dy_shorts_page.tsx"),
|
|
]
|
|
|
|
REMOTE = r'''#!/bin/bash
|
|
set -euo pipefail
|
|
python3 - <<'PY'
|
|
from pathlib import Path
|
|
pairs=[
|
|
('/tmp/_dy_shorts_schedule.py','/opt/douyinWEB/backend/app/shorts_schedule.py'),
|
|
('/tmp/_dy_shorts_pipeline.py','/opt/douyinWEB/backend/app/shorts_pipeline.py'),
|
|
('/tmp/_dy_shorts_page.tsx','/opt/douyinWEB/frontend/src/app/shorts/page.tsx'),
|
|
]
|
|
for s,d in pairs:
|
|
p=Path(s); dst=Path(d)
|
|
dst.write_bytes(p.read_bytes().replace(b'\r\n',b'\n').replace(b'\r',b'\n'))
|
|
print('ok', dst, dst.stat().st_size)
|
|
PY
|
|
python3 -m py_compile /opt/douyinWEB/backend/app/shorts_schedule.py /opt/douyinWEB/backend/app/shorts_pipeline.py && echo py_ok
|
|
systemctl restart douyinweb-api.service
|
|
sleep 6
|
|
systemctl is-active douyinweb-api.service
|
|
# Force pull-forward of parked upload_at
|
|
python3 - <<'PY'
|
|
import sys
|
|
sys.path.insert(0,'/opt/douyinWEB/backend')
|
|
from app.shorts_schedule import fleet_pace_plan, pull_forward_due_uploads
|
|
plan=fleet_pace_plan()
|
|
print('pace', {k:plan.get(k) for k in ('uploaded','front_target','need_front','behind','urgent','recommended_global_gap_sec','recommended_channel_gap_sec','recommended_per_hour','deadline_progress')})
|
|
n=pull_forward_due_uploads()
|
|
print('pulled', n)
|
|
plan2=fleet_pace_plan()
|
|
print('pace_after', {k:plan2.get(k) for k in ('uploaded','front_target','behind','recommended_global_gap_sec')})
|
|
# due count
|
|
import sqlite3, time, datetime
|
|
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={}
|
|
for r in con.execute("SELECT upload_at FROM shorts_jobs WHERE push_date=? AND status IN ('scheduled','recorded') AND IFNULL(clip_path,'')!=''",(day,)):
|
|
ua=float(r[0] 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
|
|
curl -sS -m 8 http://127.0.0.1:8014/api/ping; echo
|
|
'''
|
|
|
|
|
|
def deploy(label, host, port, user, pw, sudo=False):
|
|
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()
|
|
for local, remote in FILES:
|
|
data = (ROOT / local).read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
|
|
with sftp.file(remote, "wb") as f:
|
|
f.write(data)
|
|
with sftp.file("/tmp/_dy_pace.sh", "w") as f:
|
|
f.write(REMOTE.replace("\r\n", "\n"))
|
|
sftp.close()
|
|
cmd = f"echo '{pw}' | sudo -S -p '' bash /tmp/_dy_pace.sh" if sudo else "bash /tmp/_dy_pace.sh"
|
|
_, o, e = c.exec_command(cmd, timeout=600)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
deploy("vps-dylive", "107.173.30.245", 22, "root", "Xiao4669805", sudo=False)
|
|
deploy("phys-dy", "107.173.30.245", 4014, "eric", "4669805", sudo=True)
|
|
print("DONE")
|