Skip to content

Commit 5021c14

Browse files
committed
feat: Add timeout to the datasource for driver connected
1 parent 19d43d4 commit 5021c14

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

backend/apps/datasource/crud/datasource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def check_status(session: SessionDep, trans: Trans, ds: CoreDatasource, is_raise
6767
with dmPython.connect(user=conf.username, password=conf.password, server=conf.host,
6868
port=conf.port) as conn, conn.cursor() as cursor:
6969
try:
70-
cursor.execute('select 1').fetchall()
70+
cursor.execute('select 1', timeout=10).fetchall()
7171
SQLBotLogUtil.info("success")
7272
return True
7373
except Exception as e:

backend/apps/db/db.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def get_schema(ds: CoreDatasource):
113113
if ds.type == 'dm':
114114
with dmPython.connect(user=conf.username, password=conf.password, server=conf.host,
115115
port=conf.port) as conn, conn.cursor() as cursor:
116-
cursor.execute(f"""select OBJECT_NAME from dba_objects where object_type='SCH'""")
116+
cursor.execute(f"""select OBJECT_NAME from dba_objects where object_type='SCH'""", timeout=conf.timeout)
117117
res = cursor.fetchall()
118118
res_list = [item[0] for item in res]
119119
return res_list
@@ -206,7 +206,7 @@ def get_tables(ds: CoreDatasource):
206206
from all_tab_comments
207207
where owner='{conf.dbSchema}'
208208
AND (table_type = 'TABLE' or table_type = 'VIEW')
209-
""")
209+
""", timeout=conf.timeout)
210210
res = cursor.fetchall()
211211
res_list = [TableSchema(*item) for item in res]
212212
return res_list
@@ -326,7 +326,7 @@ def get_fields(ds: CoreDatasource, table_name: str = None):
326326
c.OWNER = '{conf.dbSchema}'
327327
"""
328328
sql2 = f" AND c.TABLE_NAME = '{table_name}'" if table_name is not None and table_name != "" else ""
329-
cursor.execute(sql1 + sql2)
329+
cursor.execute(sql1 + sql2, timeout=conf.timeout)
330330
res = cursor.fetchall()
331331
res_list = [ColumnSchema(*item) for item in res]
332332
return res_list
@@ -358,7 +358,7 @@ def exec_sql(ds: CoreDatasource | AssistantOutDsSchema, sql: str, origin_column=
358358
with dmPython.connect(user=conf.username, password=conf.password, server=conf.host,
359359
port=conf.port) as conn, conn.cursor() as cursor:
360360
try:
361-
cursor.execute(sql)
361+
cursor.execute(sql, timeout=conf.timeout)
362362
res = cursor.fetchall()
363363
columns = [field[0] for field in cursor.description] if origin_column else [field[0].lower() for
364364
field in

0 commit comments

Comments
 (0)