fix(promote_candidates): 补_exec_retry定义(DB锁自动重试)

This commit is contained in:
xxm
2026-08-22 01:30:57 +08:00
parent 8e9b280442
commit 0feb486a54
@@ -14,6 +14,22 @@ try:
except Exception: except Exception:
pass pass
import time as _time
def _exec_retry(conn, sql, params=(), retries=5, wait=2):
"""DB写操作自动重试(database is locked时指数退避)"""
for attempt in range(retries):
try:
return conn.execute(sql, params)
except sqlite3.OperationalError as e:
if "locked" in str(e).lower() and attempt < retries - 1:
_time.sleep(wait * (attempt + 1))
print(f" [DB锁重试{attempt+1}/{retries}] {wait*(attempt+1)}s", flush=True)
else:
raise
return None
DB_PATH = Path("/home/hmo/MoFin/data/mofin.db") DB_PATH = Path("/home/hmo/MoFin/data/mofin.db")
# 2026-08-10 修复参数:控制单次运行时长,防 hermes 600s 超时杀进程 # 2026-08-10 修复参数:控制单次运行时长,防 hermes 600s 超时杀进程