How can the flowable framework implement the process rollback functionality?
Flowable is a process engine that offers built-in features for implementing process rollback.
To achieve the function of process rollback, you can follow these steps:
- Historical Service
- generate a query for historical task instances
List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
.orderByTaskCreateTime()
.desc()
.list();
- Identify the target task to roll back to: Locate the target task in the list of historical tasks based on the index of the task that needs to be rolled back.
HistoricTaskInstance targetTask = historicTasks.get(targetTaskIndex);
- Service that manages the runtime of an application
- generate a query for process instances
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstanceId)
.singleResult();
ProcessInstance targetProcessInstance = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey(processInstance.getProcessDefinitionKey())
.variables(processInstance.getProcessVariables())
.start();
- Service of tasks
- finish
Task targetTask = taskService.createTaskQuery()
.processInstanceId(targetProcessInstance.getId())
.taskDefinitionKey(targetTaskKey)
.singleResult();
taskService.complete(targetTask.getId());
- Service for tasks
- finish
taskService.complete(currentTaskId);
This achieves the function of process rollback. Please make appropriate modifications and adjustments according to actual needs.