bfddfdfdfewe
This commit is contained in:
59
scripts/deploy_enrich_fix.py
Normal file
59
scripts/deploy_enrich_fix.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""把改完的 enrichment.py 复制到服务器,重建 worker,重启"""
|
||||
import os, paramiko
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect("207.57.129.228", port=19717, username="root",
|
||||
password=os.environ["REMOTE_PASS"],
|
||||
timeout=30, allow_agent=False, look_for_keys=False)
|
||||
|
||||
|
||||
def run(label, cmd, timeout=180):
|
||||
print(f"\n=== {label} ===")
|
||||
si, so, se = c.exec_command(cmd, timeout=timeout)
|
||||
out = so.read().decode(errors="replace")
|
||||
err = se.read().decode(errors="replace")
|
||||
rc = so.channel.recv_exit_status()
|
||||
if out.strip(): print(out.rstrip())
|
||||
if err.strip(): print(f"[stderr] {err.rstrip()}")
|
||||
print(f"-> rc={rc}")
|
||||
|
||||
|
||||
# 1) 复制改完的 enrichment.py 到服务器
|
||||
import base64
|
||||
# 本地读改完的 enrichment.py
|
||||
local = r"D:\selftools\diary-news\backend\app\services\llm\enrichment.py"
|
||||
with open(local, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
b64 = base64.b64encode(content.encode("utf-8")).decode("ascii")
|
||||
si, so, se = c.exec_command(f"bash -lc 'mkdir -p /srv/news/backend/app/services/llm && echo {b64} | base64 -d > /srv/news/backend/app/services/llm/enrichment.py.new && wc -l /srv/news/backend/app/services/llm/enrichment.py.new'", timeout=30)
|
||||
print("=== 1) 复制 enrichment.py.new ===")
|
||||
print(so.read().decode(errors="replace").rstrip())
|
||||
|
||||
# 备份原文件再覆盖
|
||||
si, so, se = c.exec_command("bash -lc 'cd /srv/news/backend/app/services/llm && cp -f enrichment.py enrichment.py.bak.$(date +%Y%m%d_%H%M%S) && mv enrichment.py.new enrichment.py && ls -la enrichment.py*'", timeout=10)
|
||||
print("\n=== 2) 备份 + 覆盖 ===")
|
||||
print(so.read().decode(errors="replace").rstrip())
|
||||
|
||||
# 3) 重建 worker 镜像
|
||||
run("3) docker compose build worker(增量,会很快)", "cd /srv/news && docker compose build worker", timeout=180)
|
||||
|
||||
# 4) 重启 worker
|
||||
run("4) docker compose up -d worker(只重启 worker)", "cd /srv/news && docker compose up -d worker", timeout=60)
|
||||
|
||||
# 5) 等启动
|
||||
run("5) 等 5 秒", "sleep 5 && date '+%H:%M:%S'")
|
||||
|
||||
# 6) 看 enrichment_loop 启动
|
||||
run("6) enrichment_loop 启动日志", "cd /srv/news && docker compose logs --tail=20 worker 2>&1 | grep -iE 'enrich|started|enabled'")
|
||||
|
||||
# 7) 等 30 秒,看是否开始 enrich
|
||||
run("7) 等 30 秒", "sleep 30 && date '+%H:%M:%S'")
|
||||
|
||||
# 8) 看是否有 enrich_article 日志
|
||||
run("8) enrich_article 日志", "cd /srv/news && docker compose logs --tail=200 worker 2>&1 | grep -E 'enrich_article|classify|commentary' | head -20")
|
||||
|
||||
# 9) 看 n/a 数量变化
|
||||
run("9) 当前 n/a 数量", "cd /srv/news && docker compose exec -T postgres psql -U news -d news -c \"SELECT classify_status, count(*) FROM articles GROUP BY classify_status ORDER BY count(*) DESC;\"")
|
||||
|
||||
c.close()
|
||||
print("\n🎉 修复完成")
|
||||
Reference in New Issue
Block a user