import os, paramiko PW = os.environ["REMOTE_PASS"] c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("207.57.129.228", port=19717, username="root", password=PW, timeout=15, allow_agent=False, look_for_keys=False) def run(cmd, t=60): si, so, se = c.exec_command(cmd, timeout=t) out = so.read().decode("utf-8", "replace") err = se.read().decode("utf-8", "replace") rc = so.channel.recv_exit_status() if out: print(out, end="") if err: print("[err]", err, end="", file=__import__("sys").stderr) return out rpw = run("grep ^REDIS_PASSWORD /srv/news/.env | cut -d= -f2").strip() # 重置 usage run(f"docker exec news-aggregator-redis-1 redis-cli -a '{rpw}' DEL 'translation:month:202606' 2>&1 | grep -v Warning") print("usage 重置为 0") # 找一条 article 重译 out = run("docker exec news-aggregator-postgres-1 psql -U news -d news -tA -c \"SELECT id FROM articles WHERE translation_status = 'ok' ORDER BY translation_chars DESC LIMIT 1;\"") aid = out.strip() print(f"\n重译 article {aid}...") run(f"docker exec news-aggregator-postgres-1 psql -U news -d news -c \"UPDATE articles SET translation_status = 'pending' WHERE id = {aid};\" 2>&1 | tail -2") run(f"cd /srv/news && docker exec news-aggregator-worker-1 python -c 'import asyncio; from app.workers.pipeline import translate_article; asyncio.run(translate_article({aid}))' 2>&1 | tail -5", t=60) # 看 usage out = run(f"docker exec news-aggregator-redis-1 redis-cli -a '{rpw}' GET 'translation:month:202606' 2>&1 | grep -v Warning") print(f"\n--- redis usage: {out.strip()}") # 看 article 的 translation_chars out = run(f"docker exec news-aggregator-postgres-1 psql -U news -d news -tA -c \"SELECT translation_chars FROM articles WHERE id = {aid};\"") print(f"--- article {aid} translation_chars (DB): {out.strip()}") # 实际值对比 print("\n--- /me/usage ---") import json out = run("curl -s -X POST http://localhost/api/v1/auth/login -H 'Content-Type: application/json' -d '{\"username\":\"owner\",\"password\":\"Owner2026!\"}'") token = json.loads(out)["access_token"] u = json.loads(run(f"curl -s -H 'Authorization: Bearer {token}' 'http://localhost/api/v1/me/usage'")) print(json.dumps(u, indent=2)) c.close()