From b49d1f63757bc609e06cd92d2e6af5e999f03f03 Mon Sep 17 00:00:00 2001 From: junjun Date: Thu, 26 Jun 2025 13:52:51 +0800 Subject: [PATCH] feat: add datasource timeout --- backend/apps/db/engine.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/apps/db/engine.py b/backend/apps/db/engine.py index 64cdc79f..e86756f5 100644 --- a/backend/apps/db/engine.py +++ b/backend/apps/db/engine.py @@ -13,7 +13,7 @@ from common.core.config import settings def get_engine_config(): return DatasourceConf(username=settings.POSTGRES_USER, password=settings.POSTGRES_PASSWORD, host=settings.POSTGRES_SERVER, port=settings.POSTGRES_PORT, database=settings.POSTGRES_DB, - dbSchema="public", timeout=30) + dbSchema="public", timeout=30) # read engine config def get_engine_uri(conf: DatasourceConf): @@ -23,7 +23,9 @@ def get_engine_uri(conf: DatasourceConf): def get_engine_conn(): conf = get_engine_config() db_url = get_engine_uri(conf) - engine = create_engine(db_url, connect_args={"options": f"-c search_path={conf.dbSchema}"}, pool_timeout=300, + engine = create_engine(db_url, + connect_args={"options": f"-c search_path={conf.dbSchema}", "connect_timeout": conf.timeout}, + pool_timeout=conf.timeout, pool_size=20, max_overflow=10) return engine