LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
fix for file execution tracker completed execution (#1347)
ali94baa5db1951
diff --git a/backend/workflow_manager/workflow_v2/file_execution_tasks.py b/backend/workflow_manager/workflow_v2/file_execution_tasks.pyindex e38c67454..a6240f514 100644--- a/backend/workflow_manager/workflow_v2/file_execution_tasks.py+++ b/backend/workflow_manager/workflow_v2/file_execution_tasks.py@@ -395,13 +395,22 @@ class FileExecutionTasks:destination,execution_result,)- # If stage is already completed, skip execution- return cls._build_final_result(- workflow_execution,- file_hash,- FinalOutputResult.skipped(),- workflow_file_execution,+ # If stage is already completed.+ # Skip execution since the result is already cached (For API)+ # or shared with destination (For ETL/Task)+ logger.info(+ f"File already completed. Skipping execution for execution_id: {workflow_execution.id}, "+ f"file_execution_id: {workflow_file_execution.id}, current_stage: {stage.value}"+ )+ final_result = FileExecutionResult(+ file=file_hash.file_name,+ file_execution_id=str(workflow_file_execution.id),+ error=file_execution_data.error+ or file_execution_data.stage_status.error,+ result=None,+ metadata=None,)+ return final_result# File Preparation Phasecontent_hash = cls._prepare_file_for_processing(@@ -466,6 +475,7 @@ class FileExecutionTasks:workflow_file_execution=None,error=error_msg,is_api=destination.is_api,+ destination=destination,)except Exception as error:error_msg = f"File execution failed: {error}"@@ -481,6 +491,7 @@ class FileExecutionTasks:workflow_file_execution=workflow_file_execution,error=error_msg,is_api=destination.is_api,+ destination=destination,)@classmethod@@ -510,7 +521,7 @@ class FileExecutionTasks:execution_id, file_execution_id)logger.info(- f"File execution tracker already exists for execution_id: {execution_id}, file_execution_id: {file_execution_id}"+ f"File execution tracker already exists for execution_id: {execution_id}, file_execution_id: {file_execution_id}, stage: {file_execution_data.stage_status.stage.value}")return file_execution_data@@ -542,6 +553,9 @@ class FileExecutionTasks:status: FileExecutionStageStatus,error: str | None = None,) -> None:+ logger.info(+ f"Marking file execution tracker completed status for execution_id: {execution_id}, file_execution_id: {file_execution_id}, stage: {FileExecutionStage.COMPLETED.value}, status: {status.value}, error: {error}"+ )# This is the cache ttl for completed file execution to prevent long term cacheCOMPLETED_EXECUTION_CACHE_TTL_IN_SECOND = (settings.FILE_EXECUTION_TRACKER_COMPLETED_TTL_IN_SECOND@@ -796,7 +810,6 @@ class FileExecutionTasks:workflow_log=workflow_log,error=result.error or execution_result.error,)- destination.delete_file_execution_directory()return cls._build_final_result(workflow_execution=workflow_execution,file_hash=file_hash,@@ -804,6 +817,7 @@ class FileExecutionTasks:workflow_file_execution=workflow_file_execution,error=result.error or execution_result.error,is_api=destination.is_api,+ destination=destination,)@classmethod@@ -946,6 +960,7 @@ class FileExecutionTasks:workflow_file_execution: WorkflowFileExecution | None = None,error: str | None = None,is_api: bool = False,+ destination: DestinationConnector | None = None,) -> FileExecutionResult:"""Construct and cache the final execution result."""final_result = FileExecutionResult(@@ -964,6 +979,12 @@ class FileExecutionTasks:api_result=final_result,)+ if destination:+ logger.info(+ f"Deleting file execution directory for file: '{file_hash.file_name}'"+ )+ destination.delete_file_execution_directory()+status = (FileExecutionStageStatus.SUCCESSif not errordiff --git a/unstract/core/src/unstract/core/file_execution_tracker.py b/unstract/core/src/unstract/core/file_execution_tracker.pyindex 4ccce5f0a..cdd3ef1de 100644--- a/unstract/core/src/unstract/core/file_execution_tracker.py+++ b/unstract/core/src/unstract/core/file_execution_tracker.py@@ -179,10 +179,9 @@ class FileExecutionStatusTracker:key = self.get_cache_key(data.execution_id, data.file_execution_id)logger.info(f"Setting file execution data for {key}: {data.to_serializable()}")self.redis_client.hset(key, mapping=data.to_serializable())- logger.info(- f"Setting file execution data for {key} to expire in {ttl_in_second} seconds"- )- self.redis_client.expire(key, ttl_in_second or self.CACHE_TTL_IN_SECOND)+ ttl = ttl_in_second or self.CACHE_TTL_IN_SECOND+ logger.info(f"Setting file execution data for {key} to expire in {ttl} seconds")+ self.redis_client.expire(key, ttl)def exists(self, execution_id: str, file_execution_id: str) -> bool:"""Check if file execution tracker data exists."""diff --git a/unstract/tool-sandbox/src/unstract/tool_sandbox/helper.py b/unstract/tool-sandbox/src/unstract/tool_sandbox/helper.pyindex bdb22f118..89b3308f4 100644--- a/unstract/tool-sandbox/src/unstract/tool_sandbox/helper.py+++ b/unstract/tool-sandbox/src/unstract/tool_sandbox/helper.py@@ -342,7 +342,7 @@ class ToolSandboxHelper:returnif file_execution_data.stage_status.stage != stage:logger.warning(- f"File execution data stage {file_execution_data.stage_status.stage} is not {stage} for execution_id: {self.execution_id} and file_execution_id: {file_execution_id}"+ f"Existing file execution data stage {file_execution_data.stage_status.stage} is not {stage} for execution_id: {self.execution_id} and file_execution_id: {file_execution_id}")return