Browse Source

fix(ppstructurev3): 优化结果收集逻辑和错误处理

- 修改 pid_output_file 路径构造方式,增加容错性
- 优化进程失败时的文件处理逻辑
- 在 run_single_process 函数中增加更多错误信息记录
- 统一处理各种异常情况,返回更详细的错误信息
zhch158_admin 3 tháng trước cách đây
mục cha
commit
2843fe0459
1 tập tin đã thay đổi với 17 bổ sung6 xóa
  1. 17 6
      zhch/ppstructurev3_scheduler.py

+ 17 - 6
zhch/ppstructurev3_scheduler.py

@@ -186,16 +186,16 @@ def collect_processed_files(results: List[Dict[str, Any]]) -> List[Tuple[str, st
         ...
         }
         """
-        pid_output_file = Path(result["output_dir"]) / f"process_{result['process_id']}" / f"process_{result['process_id']}.json"
+        pid_output_file = Path(result.get("output_dir", "")) / f"process_{result['process_id']}.json"
         if not pid_output_file.exists():
             print(f"⚠️ Warning: Output file not found for process {result['process_id']}: {pid_output_file}")
             if not result.get("success", False):
                 # 整个进程失败的情况
                 process_failed_files = result.get("failed_files", [])
                 processed_files.extend([(f, "fail") for f in process_failed_files if f])
-
-        pid_files = collect_pid_files(str(pid_output_file))
-        processed_files.extend(pid_files)
+        else:         
+            pid_files = collect_pid_files(str(pid_output_file))
+            processed_files.extend(pid_files)
     
     return processed_files
 
@@ -273,6 +273,11 @@ def run_single_process(args: Tuple[List[str], Dict[str, Any], int]) -> Dict[str,
                 "process_id": process_id,
                 "success": False,
                 "error": f"Process failed with return code {result.returncode}",
+                "processing_time": processing_time,
+                "file_count": len(file_chunk),
+                "device": config["device"],
+                "output_dir": str(process_output_dir),
+                "failed_files": [str(f) for f in file_chunk],
                 "stdout": result.stdout,
                 "stderr": result.stderr
             }
@@ -282,14 +287,20 @@ def run_single_process(args: Tuple[List[str], Dict[str, Any], int]) -> Dict[str,
         return {
             "process_id": process_id,
             "success": False,
-            "error": "Process timeout"
+            "error": "Process timeout",
+            "device": config["device"],
+            "output_dir": str(process_output_dir),
+            "failed_files": [str(f) for f in file_chunk]
         }
     except Exception as e:
         print(f"Process {process_id} error: {e}")
         return {
             "process_id": process_id,
             "success": False,
-            "error": str(e)
+            "error": str(e),
+            "device": config["device"],
+            "output_dir": str(process_output_dir),
+            "failed_files": [str(f) for f in file_chunk]
         }
     finally:
         # 清理临时文件