|
|
@@ -13,19 +13,17 @@ STATUS_RUNNING = 1 # 执行中
|
|
|
STATUS_SUCCESS = 2 # 成功
|
|
|
STATUS_FAILED = 3 # 失败
|
|
|
|
|
|
-# 不需要查询结果的状态
|
|
|
-STATUS_WITHOUT_RESULT = {STATUS_PENDING, STATUS_RUNNING, STATUS_FAILED}
|
|
|
+# 不需要查询结果的状态(失败状态需要查询 error_message,因此不在此集合中)
|
|
|
+STATUS_WITHOUT_RESULT = {STATUS_PENDING, STATUS_RUNNING}
|
|
|
|
|
|
|
|
|
-def _build_response(data: Dict[str, Any], reason: Optional[str] = None) -> Dict[str, Any]:
|
|
|
+def _build_response(data: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
"""构建统一响应格式"""
|
|
|
response = {
|
|
|
"code": 0,
|
|
|
"msg": "ok",
|
|
|
"data": data
|
|
|
}
|
|
|
- if reason:
|
|
|
- response["reason"] = reason
|
|
|
return response
|
|
|
|
|
|
|
|
|
@@ -54,12 +52,13 @@ def _fetch_decode_result(task_id: str) -> Optional[Dict[str, Any]]:
|
|
|
}
|
|
|
|
|
|
|
|
|
-def _build_result_data(task_id: str, status: int, result: Any = None) -> Dict[str, Any]:
|
|
|
+def _build_result_data(task_id: str, status: int, result: Any = None, reason: Optional[str] = None) -> Dict[str, Any]:
|
|
|
"""构建结果数据"""
|
|
|
return {
|
|
|
"taskId": task_id,
|
|
|
"status": status,
|
|
|
- "result": result
|
|
|
+ "result": result,
|
|
|
+ "reason": reason
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -77,12 +76,12 @@ def _handle_success_status(task_id: str, capability: int) -> Dict[str, Any]:
|
|
|
result_data = _build_result_data(
|
|
|
task_id=task_id,
|
|
|
status=STATUS_SUCCESS,
|
|
|
- result=decode_result.get("result")
|
|
|
+ result=decode_result.get("result"),
|
|
|
+ reason=decode_result.get("error_message")
|
|
|
)
|
|
|
|
|
|
return _build_response(
|
|
|
- data=result_data,
|
|
|
- reason=decode_result.get("error_message")
|
|
|
+ result_data
|
|
|
)
|
|
|
|
|
|
|
|
|
@@ -109,6 +108,25 @@ def get_decode_detail_by_task_id(task_id: str) -> Optional[Dict[str, Any]]:
|
|
|
if status == STATUS_SUCCESS:
|
|
|
return _handle_success_status(task_id_value, capability)
|
|
|
|
|
|
+ # 失败状态,需要返回 error_message 到 reason 字段,result 固定为 "[]"
|
|
|
+ if status == STATUS_FAILED:
|
|
|
+ error_message: Optional[str] = None
|
|
|
+ # 仅对解构任务从结果表中查询失败原因
|
|
|
+ if capability == CapabilityEnum.DECODE.value:
|
|
|
+ decode_result = _fetch_decode_result(task_id_value)
|
|
|
+ if decode_result:
|
|
|
+ error_message = decode_result.get("error_message")
|
|
|
+
|
|
|
+ result_data = _build_result_data(
|
|
|
+ task_id=task_id_value,
|
|
|
+ status=STATUS_FAILED,
|
|
|
+ result="[]",
|
|
|
+ reason=error_message or ""
|
|
|
+ )
|
|
|
+ return _build_response(
|
|
|
+ result_data
|
|
|
+ )
|
|
|
+
|
|
|
# 其他未知状态,返回基础数据
|
|
|
result_data = _build_result_data(task_id_value, status)
|
|
|
return _build_response(result_data)
|