Skip to content

Commit

Permalink
fix: workflow instance execute
Browse files Browse the repository at this point in the history
  • Loading branch information
kalencaya committed Mar 30, 2024
1 parent a15ff2f commit 18ddc1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
package cn.sliew.scaleph.workflow.listener.taskinstance;

import cn.sliew.scaleph.workflow.service.WorkflowTaskInstanceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.redisson.api.annotation.RInject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.concurrent.CompletableFuture;

@Slf4j
@Component
public class WorkflowTaskInstanceDeployEventListener extends AbstractWorkflowTaskInstanceEventListener {

Expand Down Expand Up @@ -62,9 +59,6 @@ public DeployRunner(WorkflowTaskInstanceEventDTO event) {
public void run() {
workflowTaskInstanceService.updateTaskId(event.getWorkflowTaskInstanceId(), taskId);
workflowTaskInstanceService.updateState(event.getWorkflowTaskInstanceId(), event.getState(), event.getNextState(), null);
if (RandomUtils.nextInt(0, 100) > 80) {
throw new RuntimeException("任务执行失败");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void run() {
for (WorkflowTaskDefinitionDTO workflowTaskDefinitionDTO : workflowTaskDefinitionDTOS) {
workflowTaskInstanceDTOS.add(workflowTaskInstanceService.deploy(workflowTaskDefinitionDTO.getId(), event.getWorkflowInstanceId()));
}
// todo 循环检测 workflowTaskInstanceDTOS 状态,判断是否成功或失败
// todo 循环检测 workflowTaskInstanceDTOS 状态或接收 workflowTaskInstance 事件,判断是否成功或失败
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import static cn.sliew.milky.common.check.Ensures.checkState;
Expand Down Expand Up @@ -75,12 +76,23 @@ public void updateState(Long id, WorkflowInstanceState state, WorkflowInstanceSt

@Override
public void updateSuccess(Long id) {

WorkflowInstance record = new WorkflowInstance();
record.setId(id);
record.setState(WorkflowInstanceState.SUCCESS);
record.setEndTime(new Date());
workflowInstanceMapper.updateById(record);
}

@Override
public void updateFailure(Long id, Throwable throwable) {

WorkflowInstance record = new WorkflowInstance();
record.setId(id);
record.setState(WorkflowInstanceState.FAILURE);
record.setEndTime(new Date());
if (throwable != null) {
record.setMessage(throwable.getMessage());
}
workflowInstanceMapper.updateById(record);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions tools/docker/mysql/init.d/scaleph-workflow-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ CREATE TABLE `workflow_instance`
(
`id` BIGINT NOT NULL AUTO_INCREMENT,
`workflow_definition_id` BIGINT NOT NULL,
`task_id` VARCHAR(128) NOT NULL,
`task_id` VARCHAR(128),
`state` VARCHAR(4) NOT NULL,
`start_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`end_time` DATETIME,
Expand Down Expand Up @@ -125,7 +125,7 @@ CREATE TABLE `workflow_task_instance`
`id` BIGINT NOT NULL AUTO_INCREMENT,
`workflow_task_definition_id` BIGINT NOT NULL,
`workflow_instance_id` BIGINT NOT NULL,
`task_id` VARCHAR(128) NOT NULL,
`task_id` VARCHAR(128),
`stage` VARCHAR(4) NOT NULL,
`start_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`end_time` DATETIME,
Expand Down

0 comments on commit 18ddc1c

Please sign in to comment.