Przeglądaj źródła

refactor(api): 重构获取任务结果接口和数据库查询逻辑

将POST方法改为GET方法,简化参数传递
修改数据库查询返回完整任务对象而非拆分字段
调整响应数据结构以直接返回任务对象
max_liu 1 dzień temu
rodzic
commit
bee2ef6f0a
2 zmienionych plików z 15 dodań i 15 usunięć
  1. 3 3
      decode_task/topicTask.py
  2. 12 12
      main.py

+ 3 - 3
decode_task/topicTask.py

@@ -26,11 +26,11 @@ def update_topic_result_by_id(param:DecodeWorkflowParam):
 
 def get_topic_result_by_id(task_id:str):
     sql = "SELECT * FROM decode_workflow WHERE task_id = %s"
-    tasks = mysql.fetchone(sql, (task_id,))
-    if not tasks:
+    task = mysql.fetchone(sql, (task_id,))
+    if not task:
         logger.info(f"task_id = {task_id} , 任务不存在")
         return None
-    return tasks['result'], tasks['task_status'],tasks['error_reason']
+    return task
 
 
 

+ 12 - 12
main.py

@@ -117,26 +117,26 @@ def update_topic_result(param: DecodeWorkflowParam):
         }   
     }
     
-@app.post("/decodeWorkflow/result")
-def get_topic_result(param: TaskStatusParam):
-    db_res = get_topic_result_by_id_db(param.task_id)
-    logger.info(f"\n查询结构结果的task_id = {param.task_id}")
 
-    if not db_res:
+
+@app.get("/decodeWorkflow/result")
+def get_topic_result(task_id: str):
+    result = get_topic_result_by_id_db(task_id)
+    logger.info(f"\n查询结构结果的task_id = {task_id}")
+
+    if not result:
         return {
             "code": -1,
             "message": '任务不存在',
             "data": None
         }
-    result, status,error_reason = db_res
+
+    status = result["task_status"]
+    error_reason = result["error_reason"]
     return {
-        "code": 0,
+        "code": status,
         "message": status == 2 and "success" or error_reason,
-        "data": {
-            "result": result,
-            "status": status,
-            "error":error_reason,
-        } 
+        "data": result
     }