feat: add datasource timeout

This commit is contained in:
junjun
2025-06-26 13:23:43 +08:00
parent 25a895607f
commit d66d21e048
6 changed files with 25 additions and 7 deletions
+3 -1
View File
@@ -73,6 +73,7 @@ class DatasourceConf(BaseModel):
filename: str = ''
sheets: List = ''
mode: str = ''
timeout: int = 30
def to_dict(self):
return {
@@ -86,7 +87,8 @@ class DatasourceConf(BaseModel):
"dbSchema": self.dbSchema,
"filename": self.filename,
"sheets": self.sheets,
"mode": self.mode
"mode": self.mode,
"timeout": self.timeout
}
+9 -3
View File
@@ -48,11 +48,17 @@ def get_uri(ds: CoreDatasource):
def get_engine(ds: CoreDatasource) -> Engine:
conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if ds.type != "excel" else get_engine_config()
if conf.timeout is None:
conf.timeout = 30
if ds.type == "pg" and (conf.dbSchema is not None and conf.dbSchema != ""):
engine = create_engine(get_uri(ds), connect_args={"options": f"-c search_path={conf.dbSchema}"},
pool_timeout=30, pool_size=20, max_overflow=10)
engine = create_engine(get_uri(ds),
connect_args={"options": f"-c search_path={conf.dbSchema}",
"connect_timeout": conf.timeout},
pool_timeout=conf.timeout, pool_size=20, max_overflow=10)
else:
engine = create_engine(get_uri(ds), pool_timeout=30, pool_size=20, max_overflow=10)
engine = create_engine(get_uri(ds), connect_args={"connect_timeout": conf.timeout}, pool_timeout=conf.timeout,
pool_size=20,
max_overflow=10)
return engine
+1 -1
View File
@@ -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")
dbSchema="public", timeout=30)
def get_engine_uri(conf: DatasourceConf):