diff --git a/deploy/profile-scripts/daily_kline_collector.py b/deploy/profile-scripts/daily_kline_collector.py index 40e8e6d6..8d4a9c92 100644 --- a/deploy/profile-scripts/daily_kline_collector.py +++ b/deploy/profile-scripts/daily_kline_collector.py @@ -138,6 +138,27 @@ def main(): written += 1 ok += 1 except Exception as e: + # 2026-08-18 database is locked 指数退避重试(工单t_17ba6f5d:sz_b整点调度撞锁致2只失败) + if "database is locked" in str(e).lower() or "locked" in str(e).lower(): + import random as _rd + _retry = 0 + _ok = False + while _retry < 3 and not _ok: + try: + time.sleep(0.5 * (2 ** _retry) + _rd.uniform(0, 0.3)) + for b in bars[-WRITE_RECENT:]: + cur.execute( + "INSERT OR REPLACE INTO stock_daily (code, date, open, close, high, low, volume) " + "VALUES (?,?,?,?,?,?,?)", + (code, b["date"], b["open"], b["close"], b["high"], b["low"], b["volume"]), + ) + conn.commit() + _ok = True + except Exception: + _retry += 1 + if _ok: + ok += 1 + continue fail += 1 if fail <= 5: print(f" FAIL {code}: {e}", flush=True)