AnsweredAssumed Answered

Rollback operations on task-complete failure

Question asked by mf on Aug 17, 2015
Latest reply on Aug 18, 2015 by martin.grofcik
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?

public class TaskManager {

   private TaskService taskService;

   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
      } catch(Exception e) {
         // revert variables
         runtimeService.removeVariableLocal(param.getExecutionId(), "var1");
         taskService.removeVariableLocal(param.getTaskId(), "var2");
         throw e;