fix: 修剩余的 (await ...)).scalar_one_or_none() 链式 + bookmark

This commit is contained in:
Mavis
2026-06-07 23:25:53 +08:00
parent 5109d6f824
commit ce903ac58e
3 changed files with 38 additions and 38 deletions

View File

@@ -1,4 +1,4 @@
import os, paramiko, json, time
import os, paramiko, time
PW = os.environ["REMOTE_PASS"]
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
@@ -15,39 +15,34 @@ def run(cmd, t=60):
print(f" rc={rc}")
return out
# 1) 取 owner 密码
run("cd /srv/news && sudo -u news git pull --rebase 2>&1 | tail -3")
# 只重建 api(代码变更)
run("cd /srv/news && sg docker -c 'docker compose up -d --force-recreate --no-deps --build api' 2>&1 | tail -5", t=120)
time.sleep(8)
# 测试登录
print("\n=== 测登录 ===")
owner_pw = run("cat /root/.owner_pass").strip()
print(f"\n=== owner 密码: {owner_pw} ===\n")
# 2) 登录拿 token
login_cmd = f"""curl -s -X POST http://localhost/api/v1/auth/login -H 'Content-Type: application/json' -d '{{"username":"owner","password":"{owner_pw}"}}'"""
login_resp = run(login_cmd)
token = json.loads(login_resp).get("access_token", "")
print(f"\n=== token(前 40): {token[:40]}... ===\n")
# 3) 触发一次抓取
print("=== 触发一次抓取 ===")
run("cd /srv/news && sg docker -c \"docker compose exec -T worker python -c 'import asyncio; from app.workers.pipeline import run_once; asyncio.run(run_once())'\" 2>&1 | tail -30", t=180)
# 4) 等翻译完成,看文章数
time.sleep(10)
print("\n=== 查文章数 ===")
run("cd /srv/news && sg docker -c \"docker compose exec -T postgres psql -U news -d news -c 'SELECT count(*) FROM articles; SELECT count(*) FROM articles WHERE translation_status = '\\''ok'\\'';'\" 2>&1 | tail -10")
# 5) 拿一条翻译好的文章
print("\n=== 拉一条文章 ===")
list_cmd = f"curl -s -H 'Authorization: Bearer {token}' http://localhost/api/v1/articles?limit=1"
art_resp = run(list_cmd)
login_cmd = f"curl -s -X POST http://localhost/api/v1/auth/login -H 'Content-Type: application/json' -d '{{\"username\":\"owner\",\"password\":\"{owner_pw}\"}}'"
out = run(login_cmd)
import json
try:
data = json.loads(art_resp)
items = data.get("items", [])
if items:
art = items[0]
print(f" id: {art['id']}")
print(f" source: {art['source']['name']}")
print(f" title (en): {art['title'][:80]}")
print(f" title (zh): {art.get('title_zh', '(none)')[:80] if art.get('title_zh') else '(none)'}")
print(f" status: {art['translation_status']}")
data = json.loads(out)
token = data.get("access_token", "")
if token:
print(f"\n[OK] 登录成功,token 前 40: {token[:40]}...")
# 测拉 articles
art = run(f"curl -s -H 'Authorization: Bearer {token}' 'http://localhost/api/v1/articles?limit=3'")
try:
ad = json.loads(art)
print(f" articles 数: {len(ad.get('items', []))}")
except Exception as e:
print(f" parse err: {e}")
print(f" raw: {art[:200]}")
else:
print(f"\n[FAIL] 登录失败,响应: {out[:300]}")
# 看 api 日志
log_out = run("cd /srv/news && sg docker -c 'docker compose logs --tail=30 api' 2>&1 | tail -20")
except Exception as e:
print(f"parse err: {e}\n raw: {art_resp[:300]}")
print(f"parse err: {e}\n raw: {out[:300]}")
c.close()