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):
+2 -1
View File
@@ -134,7 +134,8 @@
"connect": {
"success": "Connect success",
"failed": "Connect failed"
}
},
"timeout":"Timeout(second)"
}
},
"chat": {
+2 -1
View File
@@ -134,7 +134,8 @@
"connect": {
"success": "连接成功",
"failed": "连接失败"
}
},
"timeout":"查询超时(秒)"
}
},
"chat": {
+8
View File
@@ -96,6 +96,9 @@
<el-input v-model="form.dbSchema" />
<el-button v-if="false" link type="primary" :icon="Plus">Get Schema</el-button>
</el-form-item>
<el-form-item :label="t('ds.form.timeout')" prop="timeout">
<el-input-number v-model="form.timeout" :min="0" :max="300" controls-position="right" />
</el-form-item>
<span>
<span>{{ t('ds.form.support_version') }}:&nbsp;</span>
<span v-if="form.type === 'sqlServer'">2012+</span>
@@ -211,6 +214,7 @@ const form = ref<any>({
filename: '',
sheets: [],
mode: 'service_name',
timeout: 30,
})
const close = () => {
@@ -246,6 +250,7 @@ const open = (item: any, editTable: boolean = false) => {
form.value.filename = configuration.filename
form.value.sheets = configuration.sheets
form.value.mode = configuration.mode
form.value.timeout = configuration.timeout ? configuration.timeout : 30
}
if (editTable) {
@@ -304,6 +309,7 @@ const open = (item: any, editTable: boolean = false) => {
filename: '',
sheets: [],
mode: 'service_name',
timeout: 30,
}
}
dialogVisible.value = true
@@ -363,6 +369,7 @@ const buildConf = () => {
filename: form.value.filename,
sheets: form.value.sheets,
mode: form.value.mode,
timeout: form.value.timeout,
})
)
const obj = JSON.parse(JSON.stringify(form.value))
@@ -377,6 +384,7 @@ const buildConf = () => {
delete obj.filename
delete obj.sheets
delete obj.mode
delete obj.timeout
return obj
}