Первый коммит

This commit is contained in:
2026-02-25 14:47:19 +03:00
commit 1e376aff24
170 changed files with 4893 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
from __future__ import annotations
import threading
import psycopg
from langgraph.checkpoint.postgres import PostgresSaver
from psycopg.rows import dict_row
from app.modules.shared.db import database_url
_CHECKPOINTER: PostgresSaver | None = None
_LOCK = threading.Lock()
def _conn_string() -> str:
url = database_url()
if url.startswith("postgresql+psycopg"):
return url.replace("postgresql+psycopg", "postgresql", 1)
return url
def get_checkpointer() -> PostgresSaver:
global _CHECKPOINTER
with _LOCK:
if _CHECKPOINTER is None:
conn = psycopg.connect(_conn_string(), autocommit=True, row_factory=dict_row)
cp = PostgresSaver(conn)
cp.setup()
_CHECKPOINTER = cp
return _CHECKPOINTER