|
@@ -57,6 +57,7 @@ class WorkflowCycleManage:
|
|
|
_user: Union[Account, EndUser]
|
|
|
_task_state: WorkflowTaskState
|
|
|
_workflow_system_variables: dict[SystemVariableKey, Any]
|
|
|
+ _wip_workflow_node_executions: dict[str, WorkflowNodeExecution]
|
|
|
|
|
|
def _handle_workflow_run_start(self) -> WorkflowRun:
|
|
|
max_sequence = (
|
|
@@ -251,6 +252,8 @@ class WorkflowCycleManage:
|
|
|
db.session.refresh(workflow_node_execution)
|
|
|
db.session.close()
|
|
|
|
|
|
+ self._wip_workflow_node_executions[workflow_node_execution.node_execution_id] = workflow_node_execution
|
|
|
+
|
|
|
return workflow_node_execution
|
|
|
|
|
|
def _handle_workflow_node_execution_success(self, event: QueueNodeSucceededEvent) -> WorkflowNodeExecution:
|
|
@@ -275,9 +278,10 @@ class WorkflowCycleManage:
|
|
|
workflow_node_execution.elapsed_time = (workflow_node_execution.finished_at - event.start_at).total_seconds()
|
|
|
|
|
|
db.session.commit()
|
|
|
- db.session.refresh(workflow_node_execution)
|
|
|
db.session.close()
|
|
|
|
|
|
+ self._wip_workflow_node_executions.pop(workflow_node_execution.node_execution_id)
|
|
|
+
|
|
|
return workflow_node_execution
|
|
|
|
|
|
def _handle_workflow_node_execution_failed(self, event: QueueNodeFailedEvent) -> WorkflowNodeExecution:
|
|
@@ -300,9 +304,10 @@ class WorkflowCycleManage:
|
|
|
workflow_node_execution.elapsed_time = (workflow_node_execution.finished_at - event.start_at).total_seconds()
|
|
|
|
|
|
db.session.commit()
|
|
|
- db.session.refresh(workflow_node_execution)
|
|
|
db.session.close()
|
|
|
|
|
|
+ self._wip_workflow_node_executions.pop(workflow_node_execution.node_execution_id)
|
|
|
+
|
|
|
return workflow_node_execution
|
|
|
|
|
|
#################################################
|
|
@@ -678,17 +683,7 @@ class WorkflowCycleManage:
|
|
|
:param node_execution_id: workflow node execution id
|
|
|
:return:
|
|
|
"""
|
|
|
- workflow_node_execution = (
|
|
|
- db.session.query(WorkflowNodeExecution)
|
|
|
- .filter(
|
|
|
- WorkflowNodeExecution.tenant_id == self._application_generate_entity.app_config.tenant_id,
|
|
|
- WorkflowNodeExecution.app_id == self._application_generate_entity.app_config.app_id,
|
|
|
- WorkflowNodeExecution.workflow_id == self._workflow.id,
|
|
|
- WorkflowNodeExecution.triggered_from == WorkflowNodeExecutionTriggeredFrom.WORKFLOW_RUN.value,
|
|
|
- WorkflowNodeExecution.node_execution_id == node_execution_id,
|
|
|
- )
|
|
|
- .first()
|
|
|
- )
|
|
|
+ workflow_node_execution = self._wip_workflow_node_executions.get(node_execution_id)
|
|
|
|
|
|
if not workflow_node_execution:
|
|
|
raise Exception(f"Workflow node execution not found: {node_execution_id}")
|