瀏覽代碼

fix: persist workflow execution status on partial success and failure (#20264)

Signed-off-by: -LAN- <laipz8200@outlook.com>
tags/1.4.1
-LAN- 5 月之前
父節點
當前提交
55503ce771
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 21 行新增18 行删除
  1. 21
    18
      api/core/workflow/workflow_cycle_manager.py

+ 21
- 18
api/core/workflow/workflow_cycle_manager.py 查看文件

) )
) )


self._workflow_execution_repository.save(workflow_execution)
return workflow_execution return workflow_execution


def handle_workflow_run_partial_success( def handle_workflow_run_partial_success(
) )
) )


self._workflow_execution_repository.save(execution)
return execution return execution


def handle_workflow_run_failed( def handle_workflow_run_failed(
trace_manager: Optional[TraceQueueManager] = None, trace_manager: Optional[TraceQueueManager] = None,
exceptions_count: int = 0, exceptions_count: int = 0,
) -> WorkflowExecution: ) -> WorkflowExecution:
execution = self._get_workflow_execution_or_raise_error(workflow_run_id)
workflow_execution = self._get_workflow_execution_or_raise_error(workflow_run_id)


execution.status = WorkflowExecutionStatus(status.value)
execution.error_message = error_message
execution.total_tokens = total_tokens
execution.total_steps = total_steps
execution.finished_at = datetime.now(UTC).replace(tzinfo=None)
execution.exceptions_count = exceptions_count
workflow_execution.status = WorkflowExecutionStatus(status.value)
workflow_execution.error_message = error_message
workflow_execution.total_tokens = total_tokens
workflow_execution.total_steps = total_steps
workflow_execution.finished_at = datetime.now(UTC).replace(tzinfo=None)
workflow_execution.exceptions_count = exceptions_count


# Use the instance repository to find running executions for a workflow run # Use the instance repository to find running executions for a workflow run
running_domain_executions = self._workflow_node_execution_repository.get_running_executions(
workflow_run_id=execution.id
running_node_executions = self._workflow_node_execution_repository.get_running_executions(
workflow_run_id=workflow_execution.id
) )


# Update the domain models # Update the domain models
now = datetime.now(UTC).replace(tzinfo=None) now = datetime.now(UTC).replace(tzinfo=None)
for domain_execution in running_domain_executions:
if domain_execution.node_execution_id:
for node_execution in running_node_executions:
if node_execution.node_execution_id:
# Update the domain model # Update the domain model
domain_execution.status = NodeExecutionStatus.FAILED
domain_execution.error = error_message
domain_execution.finished_at = now
domain_execution.elapsed_time = (now - domain_execution.created_at).total_seconds()
node_execution.status = NodeExecutionStatus.FAILED
node_execution.error = error_message
node_execution.finished_at = now
node_execution.elapsed_time = (now - node_execution.created_at).total_seconds()


# Update the repository with the domain model # Update the repository with the domain model
self._workflow_node_execution_repository.save(domain_execution)
self._workflow_node_execution_repository.save(node_execution)


if trace_manager: if trace_manager:
trace_manager.add_trace_task( trace_manager.add_trace_task(
TraceTask( TraceTask(
TraceTaskName.WORKFLOW_TRACE, TraceTaskName.WORKFLOW_TRACE,
workflow_execution=execution,
workflow_execution=workflow_execution,
conversation_id=conversation_id, conversation_id=conversation_id,
user_id=trace_manager.user_id, user_id=trace_manager.user_id,
) )
) )


return execution
self._workflow_execution_repository.save(workflow_execution)
return workflow_execution


def handle_node_execution_start( def handle_node_execution_start(
self, self,

Loading…
取消
儲存