fix(translate): pipeline 写库用 service 返回的 engine(之前写死 tencent)

pipeline.translate_article 调 translation_service.translate() 后,
自己写 engine_label='tencent',忽略 service 实际返回的 engine。
效果:即使 service 内部按 spark 优先链路跑成功了,
DB 里 translation_engine 也只显示 tencent。

修法: 改用 tr_title.engine(or 默认 tencent 兜底)。

附带: deploy_pull.py 加 sys.stdout.reconfigure(encoding='utf-8'),
Windows GBK 终端下 Unicode 字符不会再 UnicodeEncodeError。
This commit is contained in:
Mavis
2026-06-10 23:31:03 +08:00
parent b27643123e
commit a8e93cf7c7
2 changed files with 20 additions and 12 deletions

View File

@@ -182,7 +182,8 @@ async def translate_article(article_id: int) -> None:
translated_chunks.append(tr.text) translated_chunks.append(tr.text)
tr_body = "\n\n".join(translated_chunks) tr_body = "\n\n".join(translated_chunks)
engine_label = "tencent" # 用 service 返回的 engine 标签(spark / tencent / tencent_maas / agnes / nllb / cache)
engine_label = tr_title.engine or "tencent"
status = "ok" if (tr_title.text and tr_body) else "partial" status = "ok" if (tr_title.text and tr_body) else "partial"
except Exception as e: except Exception as e:
logger.exception("translate article %s failed: %s", article_id, e) logger.exception("translate article %s failed: %s", article_id, e)

View File

@@ -24,6 +24,13 @@ import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
# 在 Windows GBK 终端下也能正常输出中文/Unicode
try:
sys.stdout.reconfigure(encoding="utf-8")
sys.stderr.reconfigure(encoding="utf-8")
except Exception:
pass
import paramiko import paramiko
# ===== 默认配置(适配当前项目)===== # ===== 默认配置(适配当前项目)=====
@@ -92,7 +99,7 @@ def deploy(
print(f"=== 连接 {user}@{host}:{port} ===") print(f"=== 连接 {user}@{host}:{port} ===")
c = _connect(host, port, user, ssh_key) c = _connect(host, port, user, ssh_key)
print(f" 已免密登录") print(f"[OK] 已免密登录")
try: try:
# 1) 手动回退 # 1) 手动回退
@@ -100,9 +107,9 @@ def deploy(
print(f"\n=== 手动回退到 {rollback[:12]} ===") print(f"\n=== 手动回退到 {rollback[:12]} ===")
rc, out, err = _run(c, f"cd {repo_dir} && git reset --hard {rollback}", timeout=30) rc, out, err = _run(c, f"cd {repo_dir} && git reset --hard {rollback}", timeout=30)
if rc != 0: if rc != 0:
print(f" 回退失败: {err}") print(f"[FAIL] 回退失败: {err}")
return 1 return 1
print(" 已回退") print("[OK] 已回退")
rc, head, _ = _run(c, f"cd {repo_dir} && git rev-parse HEAD", timeout=10) rc, head, _ = _run(c, f"cd {repo_dir} && git rev-parse HEAD", timeout=10)
print(f"现在 HEAD: {head.strip()[:12]}") print(f"现在 HEAD: {head.strip()[:12]}")
return 0 return 0
@@ -135,7 +142,7 @@ def deploy(
rc, out, err = _run(c, cmd, timeout=180) rc, out, err = _run(c, cmd, timeout=180)
if rc != 0: if rc != 0:
print(f" {action} 失败 (rc={rc})") print(f"[FAIL] {action} 失败 (rc={rc})")
if out.strip(): print(f"stdout:\n{out}") if out.strip(): print(f"stdout:\n{out}")
if err.strip(): print(f"stderr:\n{err}") if err.strip(): print(f"stderr:\n{err}")
# 回滚(只在 pull 时) # 回滚(只在 pull 时)
@@ -143,12 +150,12 @@ def deploy(
print(f"\n=== 回退到 {before_sha[:12]} ===") print(f"\n=== 回退到 {before_sha[:12]} ===")
rrc, _, rerr = _run(c, f"cd {repo_dir} && git reset --hard {before_sha}", timeout=30) rrc, _, rerr = _run(c, f"cd {repo_dir} && git reset --hard {before_sha}", timeout=30)
if rrc == 0: if rrc == 0:
print(f" 已回退到 {before_sha[:12]}") print(f"[OK] 已回退到 {before_sha[:12]}")
else: else:
print(f" 回退失败: {rerr}") print(f"[FAIL] 回退失败: {rerr}")
return 1 return 1
print(f" {action} 成功") print(f"[OK] {action} 成功")
if out.strip(): print(out) if out.strip(): print(out)
# 5) 拉后状态 # 5) 拉后状态
@@ -162,9 +169,9 @@ def deploy(
rc, status, _ = _run(c, f"cd {repo_dir} && git status --porcelain", timeout=10) rc, status, _ = _run(c, f"cd {repo_dir} && git status --porcelain", timeout=10)
if status.strip(): if status.strip():
print(f" working tree 不干净:\n{status}") print(f"[WARN] working tree 不干净:\n{status}")
else: else:
print(" working tree 干净") print("[OK] working tree 干净")
# 6) 跟本地 main 对比 # 6) 跟本地 main 对比
local = _local_head() local = _local_head()
@@ -172,9 +179,9 @@ def deploy(
print(f"本地 HEAD: {local[:12]}") print(f"本地 HEAD: {local[:12]}")
print(f"服务器 HEAD: {head_sha[:12]}") print(f"服务器 HEAD: {head_sha[:12]}")
if local.startswith(head_sha): if local.startswith(head_sha):
print(" 服务器 == 本地") print("[OK] 服务器 == 本地")
else: else:
print(" 服务器跟本地不完全一致(可能本地未推送,或服务器在另一条 commit 上)") print("[INFO] 服务器跟本地不完全一致(可能本地未推送,或服务器在另一条 commit 上)")
# 7) 总结 # 7) 总结
print(f"\n=== 部署报告 ===") print(f"\n=== 部署报告 ===")