浏览代码

增加数据源前进行测试连接

liweiquan 2 年之前
父节点
当前提交
f6f1f9d7de
共有 2 个文件被更改,包括 19 次插入7 次删除
  1. 6 2
      app/crud/job_jdbc_datasource.py
  2. 13 5
      app/services/datax.py

+ 6 - 2
app/crud/job_jdbc_datasource.py

@@ -71,7 +71,9 @@ def create_job_jdbc_datasource(db: Session, item: schemas.JobJdbcDatasourceCreat
     if item.jdbc_password and item.jdbc_password != '':
         item.jdbc_password = decode_base64(item.jdbc_password)
     ds, item = _format_datasource(db, item)
-
+    con_result = ds.is_connect()
+    if not con_result:
+        raise Exception('连接失败,不允许添加')
     create_time: int = int(time.time())
     name_item = db.query(models.JobJdbcDatasource).filter(models.JobJdbcDatasource.datasource_name == item.datasource_name).first()
     if name_item:
@@ -118,7 +120,9 @@ def update_job_jdbc_datasources(db: Session, ds_id: int, update_item: schemas.Jo
         update_item.jdbc_password = decode_base64(update_item.jdbc_password)
         print(update_item.jdbc_password)
     ds, update_item = _format_datasource(db, update_item)
-
+    con_result = ds.is_connect()
+    if not con_result:
+        raise Exception('连接失败,不允许添加')
     db_item = db.query(models.JobJdbcDatasource).filter(models.JobJdbcDatasource.id == ds_id).first()
     if not db_item:
         raise Exception('未找到该数据源')

+ 13 - 5
app/services/datax.py

@@ -34,11 +34,19 @@ def datax_create_task(job_info: models.JobInfo):
     if job_info.partition_info is not None and job_info.partition_info != '':
         partition_list = job_info.partition_info.split(',')
     envs = {}
-    if job_info.inc_start_time and job_info.last_time and len(partition_list) > 0 and job_info.current_time:
-        envs = {
-            "first_begin_time": job_info.inc_start_time,
-            "last_key": job_info.last_time,
-            "current_key": job_info.current_time,
+    first_begin_time = int(time.time())
+    if job_info.inc_start_time is not None and job_info.inc_start_time != '':
+        first_begin_time = job_info.inc_start_time
+    last_key = 'lastTime'
+    if job_info.last_time is not None and job_info.last_time != '':
+        last_key = job_info.last_time
+    current_key = 'currentTime'
+    if job_info.current_time is not None and job_info.current_time != '':
+        current_key = job_info.current_time
+    envs = {
+            "first_begin_time": first_begin_time,
+            "last_key": last_key,
+            "current_key": current_key,
             "partition_key": "partition",
             "partition_word": partition_list[0] if len(partition_list) > 0 else '',
             "partition_format": partition_list[2]  if len(partition_list) > 0 else '',