LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
Add result acknowledgment for API deployment task (#894)
ali9d772a403854
diff --git a/backend/api_v2/api_deployment_views.py b/backend/api_v2/api_deployment_views.pyindex 18654bb6d..fddf8d536 100644--- a/backend/api_v2/api_deployment_views.py+++ b/backend/api_v2/api_deployment_views.py@@ -88,6 +88,9 @@ class DeploymentExecution(views.APIView):response_status = status.HTTP_200_OKif not include_metadata:response.remove_result_metadata_keys()+ if response.result_acknowledged:+ response_status = status.HTTP_406_NOT_ACCEPTABLE+ response.result = "Result already acknowledged"return Response(data={"status": response.execution_status,diff --git a/backend/workflow_manager/workflow_v2/dto.py b/backend/workflow_manager/workflow_v2/dto.pyindex b1d8fab12..1f98f78d6 100644--- a/backend/workflow_manager/workflow_v2/dto.py+++ b/backend/workflow_manager/workflow_v2/dto.py@@ -32,6 +32,7 @@ class ExecutionResponse:mode: Optional[str] = Noneresult: Optional[Any] = Nonemessage: Optional[str] = None+ result_acknowledged: bool = Falsedef __post_init__(self) -> None:self.log_id = self.log_id or Nonediff --git a/backend/workflow_manager/workflow_v2/migrations/0003_workflowexecution_result_acknowledged.py b/backend/workflow_manager/workflow_v2/migrations/0003_workflowexecution_result_acknowledged.pynew file mode 100644index 000000000..b329c2ac7--- /dev/null+++ b/backend/workflow_manager/workflow_v2/migrations/0003_workflowexecution_result_acknowledged.py@@ -0,0 +1,18 @@+# Generated by Django 4.2.1 on 2024-12-12 15:08++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ("workflow_v2", "0002_remove_workflow_llm_response_and_more"),+ ]++ operations = [+ migrations.AddField(+ model_name="workflowexecution",+ name="result_acknowledged",+ field=models.BooleanField(db_comment="Result acknowledged", default=False),+ ),+ ]diff --git a/backend/workflow_manager/workflow_v2/models/execution.py b/backend/workflow_manager/workflow_v2/models/execution.pyindex 7a41dfc22..c86a2a081 100644--- a/backend/workflow_manager/workflow_v2/models/execution.py+++ b/backend/workflow_manager/workflow_v2/models/execution.py@@ -48,6 +48,9 @@ class WorkflowExecution(BaseModel):)# TODO: Restrict with an enumstatus = models.CharField(default="", db_comment="Current status of execution")+ result_acknowledged = models.BooleanField(+ default=False, db_comment="Result acknowledged"+ )error_message = models.CharField(max_length=EXECUTION_ERROR_LENGTH,blank=True,diff --git a/backend/workflow_manager/workflow_v2/workflow_helper.py b/backend/workflow_manager/workflow_v2/workflow_helper.pyindex 3a119e875..5adb81a7e 100644--- a/backend/workflow_manager/workflow_v2/workflow_helper.py+++ b/backend/workflow_manager/workflow_v2/workflow_helper.py@@ -358,8 +358,9 @@ class WorkflowHelper:f"with workflow execution: {workflow_execution}")- @staticmethod+ @classmethoddef get_status_of_async_task(+ cls,execution_id: str,) -> ExecutionResponse:"""Get celery task status.@@ -381,13 +382,39 @@ class WorkflowHelper:result = AsyncResult(str(execution.task_id))task = AsyncResultData(async_result=result)- return ExecutionResponse(++ # Prepare the initial response with the task's current status and result.+ result_response = ExecutionResponse(execution.workflow_id,execution_id,execution.status,result=task.result,+ result_acknowledged=execution.result_acknowledged,)+ # If task is complete, handle acknowledgment and forgetting the+ if result.ready():+ result.forget() # Remove the result from the result backend.+ cls._set_result_acknowledge(execution)+ return result_response++ @staticmethod+ def _set_result_acknowledge(execution: WorkflowExecution) -> None:+ """Mark the result as acknowledged and update the database.++ This method is called once the task has completed and its result is forgotten.+ It ensures that the task result is flagged as acknowledged in the database++ Args:+ execution (WorkflowExecution): WorkflowExecution instance+ """+ if not execution.result_acknowledged:+ execution.result_acknowledged = True+ execution.save()+ logger.info(+ f"ExecutionID [{execution.id}] - Task {execution.task_id} acknowledged"+ )+@staticmethoddef execute_workflow_async(workflow_id: str,