AnsweredAssumed Answered

Pausing a process with a TimerStartEvent

Question asked by rgareau on Jun 27, 2012
Latest reply on Jun 28, 2012 by rgareau
Hi, when I load into my process engine a process that is started with a TimerStartEvent that is configured with a Time cycle of "R/2012/PT10S" (Every 10 seconds in 2012)

If I want to pause the process temporarily.  I've tried a couple of things but I'm having troubles preventing the timer from firing.

Here is what I've tried
repositoryService.suspendProcessDefinitionById

runtimeService.suspendProcessInstanceById

managementService.setJobRetries(jobId, 0)

But, the timer keep firing every 10 seconds.

I'm using Activiti 5.9 with org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration with jobExecutorActivate = true in a junit test.

Here is the process definition that I'm testing with
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="process1" name="process1">
    <startEvent id="timerstartevent1" name="Timer start">
      <timerEventDefinition>
        <timeCycle>R/2012/PT10S</timeCycle>
      </timerEventDefinition>
    </startEvent>

    <scriptTask id="scripttask1" name="Script Task" scriptFormat="groovy">
      <script><![CDATA[System.out.println("Date :" + new Date());]]></script>
    </scriptTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="timerstartevent1" targetRef="scripttask1"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="scripttask1" targetRef="endevent1"></sequenceFlow>
  </process>
</definitions>


—-

Here's the Junit test that I use
    @Test
    public void stoppingTimerStartedProcess() throws Exception {
        RepositoryService repositoryService = activitiRule.getRepositoryService();
        RuntimeService runtimeService = activitiRule.getRuntimeService();
        ManagementService managementService = activitiRule.getManagementService();

        repositoryService.createDeployment()
                .addInputStream("TimerStartedProcess.bpmn20.xml", new FileInputStream(timerStartedProcessFilename))
                .deploy();

        List<ProcessDefinition> procDefs = repositoryService.createProcessDefinitionQuery().list();
        repositoryService.suspendProcessDefinitionById(procDefs.get(0).getId());

        System.out.println("Pausing for 15 seconds");
        Thread.sleep(15000);

        List<Job> jobList = managementService.createJobQuery().list();
        managementService.setJobRetries(jobList.get(0).getId(), 0);

        System.out.println("Pausing for 15 seconds");
        Thread.sleep(15000);

        List<ProcessInstance> procList = runtimeService.createProcessInstanceQuery().list();
        if (procList.size() > 0) {
            runtimeService.suspendProcessInstanceById(procList.get(0).getProcessInstanceId());
        } else {
            System.out.println("procList is empty");
        }

        List<Execution> execList = runtimeService.createExecutionQuery().list();
        if (execList.size() > 0) {
            runtimeService.suspendProcessInstanceById(execList.get(0).getProcessInstanceId());
        } else {
            System.out.println("execList is empty");
        }

        System.out.println("Pausing for 20 seconds");
        Thread.sleep(20000);

    }

Outcomes