Signed-off-by: Dinger <quantdinger@gmail.com>
This commit is contained in:
Dinger
2026-03-25 13:27:48 +08:00
parent 2d969d6661
commit c0cb332432
55 changed files with 827 additions and 255 deletions
@@ -222,6 +222,16 @@ class PostgresConnection:
logger.warning(f"Failed to return connection to pool: {e}")
def _ensure_session_utc(conn) -> None:
"""每条连接检出后固定为 UTC,与 API 序列化约定一致。"""
try:
cur = conn.cursor()
cur.execute("SET TIME ZONE 'UTC'")
cur.close()
except Exception as e:
logger.warning(f"Could not SET TIME ZONE UTC on connection: {e}")
@contextmanager
def get_pg_connection():
"""
@@ -231,6 +241,7 @@ def get_pg_connection():
conn = None
try:
conn = pool.getconn()
_ensure_session_utc(conn)
pg_conn = PostgresConnection(conn)
yield pg_conn
except Exception as e:
@@ -258,6 +269,7 @@ def get_pg_connection_sync() -> PostgresConnection:
"""
pool = _get_connection_pool()
conn = pool.getconn()
_ensure_session_utc(conn)
return PostgresConnection(conn)