feat: preflight新增DB死锁检测+修复同步遗漏

This commit is contained in:
知微
2026-07-08 23:27:26 +08:00
parent e8fa355485
commit 0f3b555cbd
+17
View File
@@ -143,6 +143,21 @@ def check_cron_timestamps():
pass
check("cron过期检查", stale_count == 0, f"{stale_count}个cron长时间未正常运行" if stale_count else "")
# ── 6. DB死锁检测 ──
def check_db_locks():
"""检查最近24小时是否有 database is locked 错误"""
try:
import subprocess
r = subprocess.run(
["sudo", "journalctl", "-u", "xmpp-zhiwei", "--since", "24 hours ago", "--no-pager"],
capture_output=True, text=True, timeout=30
)
locked_lines = [l for l in r.stdout.split("\n") if "database is locked" in l.lower()]
check("DB死锁: 24h内lock错误", len(locked_lines) == 0,
f"发现{len(locked_lines)}次: {locked_lines[0][:120]}" if locked_lines else "")
except Exception as e:
check("DB死锁检查", False, str(e))
if __name__ == "__main__":
print("🔍 MoFin 开盘前验证", datetime.now().strftime("%m-%d %H:%M"))
print("=" * 40)
@@ -150,6 +165,8 @@ if __name__ == "__main__":
check_imports()
check_db()
check_smoke()
check_cron_timestamps()
check_db_locks()
# 汇总
print()