Skip to content

Commit

Permalink
feature: update workflow task dag
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqi committed Apr 11, 2024
1 parent 8f369c1 commit e925b4d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public static class DeployRunner implements Runnable, Serializable {
private WorkflowInstanceService workflowInstanceService;
@Autowired
private WorkflowTaskInstanceService workflowTaskInstanceService;
@Autowired
private WorkflowInstanceStateMachine stateMachine;

public DeployRunner(WorkflowInstanceEventDTO event) {
this.event = event;
Expand All @@ -82,6 +84,11 @@ public void run() {

// 找到 root 节点,批量启动 root 节点
Graph<WorkflowTaskDefinitionDTO2> dag = workflowDefinitionService.getDag(workflowDefinitionDTO.getId());
// 无节点,直接成功
if (dag.nodes().size() == 0) {
stateMachine.onSuccess(workflowInstanceDTO);
return;
}
Graph<WorkflowTaskInstanceDTO> workflowTaskInstanceGraph = workflowTaskInstanceService.initialize(event.getWorkflowInstanceId(), dag);

Set<WorkflowTaskInstanceDTO> nodes = workflowTaskInstanceGraph.nodes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private MutableGraph<WorkflowTaskDefinitionDTO2> buildGraph(Long id, DagDTO dag)
MutableGraph<WorkflowTaskDefinitionDTO2> graph = GraphBuilder.directed().build();
List<DagStepDTO> steps = dag.getSteps();
List<DagLinkDTO> links = dag.getLinks();
if (CollectionUtils.isEmpty(steps) || CollectionUtils.isEmpty(links)) {
if (CollectionUtils.isEmpty(steps)) {
return graph;
}
Map<String, WorkflowTaskDefinitionDTO2> stepMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,15 @@ public void updateTaskId(Long id, String taskId) {

@Override
public Graph<WorkflowTaskInstanceDTO> initialize(Long workflowInstanceId, Graph<WorkflowTaskDefinitionDTO2> graph) {
for (WorkflowTaskDefinitionDTO2 node : graph.nodes()) {
createWorkflowTaskInstance(workflowInstanceId, node);
try {
for (WorkflowTaskDefinitionDTO2 node : graph.nodes()) {
createWorkflowTaskInstance(workflowInstanceId, node);
}
return getDag(workflowInstanceId, graph);
} catch (Exception e) {
e.printStackTrace();
}
return getDag(workflowInstanceId, graph);
return null;
}

private WorkflowTaskInstanceDTO createWorkflowTaskInstance(Long workflowInstanceId, WorkflowTaskDefinitionDTO2 node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public void afterPropertiesSet() throws Exception {
.to(WorkflowInstanceState.RUNNING)
.on(WorkflowInstanceEvent.COMMAND_DEPLOY)
.perform(doPerform());
builder.externalTransition()
.from(WorkflowInstanceState.PENDING)
.to(WorkflowInstanceState.SUCCESS)
.on(WorkflowInstanceEvent.PROCESS_SUCCESS)
.perform(doPerform());

builder.internalTransition()
.within(WorkflowInstanceState.RUNNING)
Expand Down

0 comments on commit e925b4d

Please sign in to comment.