""" Stub implementations of worker core functions. Used when WORKER_MODE=stub, allowing development and testing of Scheduler / Queue / UI without requiring the Kneron Toolchain environment. Each stub: - Sleeps to simulate processing time - Creates a minimal output file - Returns a result dict matching the real core function signature """ import os import time from typing import Any, Dict def process_onnx_core_stub( input_paths: Dict[str, str], output_path: str, parameters: Dict[str, Any], ) -> Dict[str, Any]: """Stub ONNX processing: sleep 2s, create a fake out.onnx.""" file_path = input_paths["file_path"] if not os.path.exists(file_path): raise FileNotFoundError(f"Input file not found: {file_path}") os.makedirs(os.path.dirname(output_path), exist_ok=True) time.sleep(2) # Create minimal valid-looking output with open(output_path, "wb") as f: f.write(b"STUB_ONNX_OUTPUT_" + os.path.basename(file_path).encode()) return { "file_path": output_path, "file_size": os.path.getsize(output_path), "eval_report": "", "model_info": { "model_id": parameters.get("model_id"), "version": parameters.get("version"), "platform": parameters.get("platform"), }, } def process_bie_core_stub( input_paths: Dict[str, str], output_path: str, parameters: Dict[str, Any], ) -> Dict[str, Any]: """Stub BIE processing: sleep 3s, create a fake out.bie.""" onnx_file_path = input_paths["onnx_file_path"] data_dir = input_paths["data_dir"] if not os.path.exists(onnx_file_path): raise FileNotFoundError(f"ONNX file not found: {onnx_file_path}") os.makedirs(os.path.dirname(output_path), exist_ok=True) # Count ref images (if any) img_count = 0 if os.path.isdir(data_dir): img_count = len([f for f in os.listdir(data_dir) if os.path.isfile(os.path.join(data_dir, f))]) time.sleep(3) with open(output_path, "wb") as f: f.write(b"STUB_BIE_OUTPUT") return { "file_path": output_path, "file_size": os.path.getsize(output_path), "model_info": { "model_id": parameters.get("model_id"), "version": parameters.get("version"), "platform": parameters.get("platform"), }, "analysis_info": { "input_name": "stub_input", "batch_size": 1, "channels": 3, "height": 224, "width": 224, }, "processed_images": img_count, } def process_nef_core_stub( input_paths: Dict[str, str], output_path: str, parameters: Dict[str, Any], ) -> Dict[str, Any]: """Stub NEF processing: sleep 2s, create a fake out.nef.""" bie_file_path = input_paths["bie_file_path"] if not os.path.exists(bie_file_path): raise FileNotFoundError(f"BIE file not found: {bie_file_path}") os.makedirs(os.path.dirname(output_path), exist_ok=True) time.sleep(2) with open(output_path, "wb") as f: f.write(b"STUB_NEF_OUTPUT") return { "file_path": output_path, "file_size": os.path.getsize(output_path), "model_info": { "model_id": parameters.get("model_id"), "version": parameters.get("version"), "platform": parameters.get("platform"), }, "compilation_info": { "optimization_level": "stub", "memory_usage": "stub", "inference_speed": "stub", }, }