Fix comparison pipeline event and transaction handling

This commit is contained in:
“Naeel”
2026-08-27 11:23:14 +03:00
parent e5c7c88073
commit 811be85efe
6 changed files with 71 additions and 28 deletions
+19 -1
View File
@@ -10,12 +10,29 @@ import sqlite3
import threading
import time
import os
from contextlib import contextmanager
DB_PATH = "/tmp/contracts.db"
_db_session_key = None
_local = threading.local()
@contextmanager
def transaction():
"""Run DB writes atomically on the current thread connection."""
conn = get_conn()
conn.execute("BEGIN IMMEDIATE")
_local.in_transaction = True
try:
yield conn
conn.commit()
except Exception:
conn.rollback()
raise
finally:
_local.in_transaction = False
def init_db():
"""Создать/пересоздать БД + схему. Вызывается при старте и после cleanup."""
global _db_session_key
@@ -171,7 +188,8 @@ def execute(sql, params=None):
conn = get_conn()
sql = _pg_to_sqlite(sql)
cur = conn.execute(sql, params or [])
conn.commit()
if not getattr(_local, "in_transaction", False):
conn.commit()
return cur.rowcount