cancel
Showing results for 
Search instead for 
Did you mean: 

Rollback operations on task-complete failure

mf
Confirmed Champ
Confirmed Champ
I have a completeTask method in TaskManager spring bean, which first it sets some variables, then completes the task. When taskService.completeTask throws an Exception, how can i revert all operations before it?

My current solution is catching exception, removing variables, throw it again, but is there any better solution?


@Named
public class TaskManager {

   @Inject
   private TaskService taskService;

   @Inject
   private RuntimeService runtimeService;

   public void completeTask(CompleteTaskParam param) {
      // set some local variables on execution and task, for example:
      runtimeService.setVariableLocal(param.getExecutionId(), "var1", "1234");
      taskService.setVariableLocal(param.getTaskId(), "var2", "3456");
      try {
         // completing task
         taskService.complete(param.getTaskId());
      } catch(Exception e) {
         // revert variables
         runtimeService.removeVariableLocal(param.getExecutionId(), "var1");
         taskService.removeVariableLocal(param.getTaskId(), "var2");
         throw e;
      }
   }
}
1 REPLY 1