Resetting Boundary Timer

I have a boundary timer attached to a human task ,with cycle set as “R5/PT1M”. This means the timer will fire 5 times at an interval of 1 minute.
I have a situation where, this same human task can be reassigned. When so happens I need the timer to be reset . i.e It should again trigger 5 times at an interval of 1 min.
I am using this, but sadly even after reassign the timer is triggereing a total of 5 times. Need some help here. Thanks in advance

	  Job timer1=managementService.createJobQuery().processInstanceId(instanceId).timers().singleResult();
	    System.out.println("JOBS :: " + timer1);
			Calendar date = Calendar.getInstance();
			long t= date.getTimeInMillis();
			Date afterAddingOneMins=new Date(t + (1 * 60000));
			try {
				execution.getProcessEngineServices().getManagementService().suspendJobByJobDefinitionId(timer1.getId());
				
				
				execution.getProcessEngineServices().getManagementService().setJobDuedate(timer1.getId(), afterAddingOneMins);
				execution.getProcessEngineServices().getManagementService().setJobRetries(timer1.getId(), 5);
				
				}

I figured this out…different approach altogether…Let me know if anyone needs help with similar issue. Will be happy to help :slight_smile:

1 Like

Hi @Shatabdi_Dutta_IN

I have a situation in which i have to stop/reset a timer event and start again after some pending tasks(subprocess) completes . Can we do it programatically?

I am deciding escalation for each User Tasks in a process dynamically while creating BPMN. Each user task can call a subprocess. if a user calls subprocess their escalation timer should be stopped and when subprocess completes it should get started again.

can we reset and restart boundary timer event in camunda in a running process?

Hi Prashant,

Yes we can. Boundary Timer is reset, if the task is assigned back to the task hosting the timer again. This being said, this is not generally a desired solution as, the new task will be an entirely different task with a different task id .
I went through your requirement will try to think if I have something on that but, I will tell you how I solved a similar problem.

  1. Before Human Task say Task1 which is to be timed using the boundary timer, initialise a variable with value 0 using Script task.
    execution.setVariable(“abc”,0);
  2. Create a Event Subprocess with Conditional start event , having condition ${abc== 1}, i.e the process starts when value of variable abc is set to 1. In the subprocess create just a Human Task say Task2 having the boundary timer.
  3. Now, In main process, on assignment of Task1, use a delegate expression to find any instance of Task2 that is open and complete it (This will ensure, that earlier initialised instance of Boundary Timer is terminated )
    List task = taskService.createTaskQuery().processInstanceId(execution.getProcessInstanceId()).taskName(“Task2”).list();
    for(int i=0;i<task.size();i++){
    taskService.complete(task.get(i).getId());
    System.out.println(“task completed is with id:”+task.get(i).getId()+“and name”+task.get(i).getName());
    }

and then in same delegate, update the value of variable abc to 1.
runtimeService.setVariable(execution.getProcessInstanceId(),“abc”,1);

What will happen is once the task is created initially for the first time, i.e Task1 , the delegate expression is invoked which will try to find and complete instances of Task2( There is none now) and thereafter sets the value of variable abc to 1. On setting value of abc to 1, event Subprocess is invoked. This creates an instance of Task2 and also initialises the Boundary timer. Now when u Reassign Task1, The delegate expression is again invoked, which will again try to find and complete instances of Task2 (This time we have one). Once this instance is completed previously started timer also is deleted/stopped and when the variable abc is set to 1 again, a new instance of the event subprocess starts.

  1. Now. at the very end, on completion and deletion of Task1, use delegate expression to complete any open instance of Task2

Hope this helps.

Hi @Shatabdi_Dutta_IN, I need to reset the timer on task re assign, can you please help me on this.