cancel
Showing results for 
Search instead for 
Did you mean: 

timer to fire receiveTask

javacorner
Champ in-the-making
Champ in-the-making
Dears,

I am implementing business workflow
my process is calling <strong>external system </strong>
I have to find some way to fix the case of the <strong>external system </strong> doesn't reply .
I am trying to use the solution of <em>jbarrez</em> at <a>http://forums.activiti.org/comment/14426#comment-14426</a>
<!–break–>
I added  <em>receiveTask</em> in case of error in<strong>external system </strong> call failure like following
<blockcode>
<receiveTask id="waitTimer" name="wait for timer"></receiveTask>
    <exclusiveGateway id="isCallBackendSuccess" name="Is Call Backend Success"></exclusiveGateway>
    <sequenceFlow id="continue" name="continue" sourceRef="isCallBackendSuccess" targetRef="servicetaskContinue">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${backendAnswered== true}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="backerror" name="backerror" sourceRef="isCallBackendSuccess" targetRef="waitTimer">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${backendAnswered== false}]]></conditionExpression>
    </sequenceFlow>
</blockcode>
<!–break–>
I created another process "cleanup " that will fire after time duration to search about all process instances that are waiting at "receiveTask" to send  "signal" to them to try to call the<strong>external system </strong> again like following
<blockcode>
<process id="timerCleanup" name="TimerCleanup" isExecutable="true">
    <startEvent id="timerstartevent1" name="Timer start">
      <timerEventDefinition>
        <timeDuration>PT2M</timeDuration>
      </timerEventDefinition>
    </startEvent>
    <serviceTask id="cleanupTask" name="cleanupTask" activiti:class="me.ffusion.bpm.javaDelegates.Cleanup"></serviceTask>
    <sequenceFlow id="flow1" sourceRef="timerstartevent1" targetRef="cleanupTask"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" sourceRef="cleanupTask" targetRef="endevent1"></sequenceFlow>
  </process>
</blockcode>
<!–break–>
my question is how to implement the java delegate for the timer "cleanupTask" to about all process instances that are waiting at "receiveTask" to send  "signal" to them to try to call the external system again.

I want to loop for all these instances and run the following statement .
   
runtimeService.signal(waitStateExecution.getId());

1 REPLY 1

javacorner
Champ in-the-making
Champ in-the-making
Hello All,

I created That code which is OK .
<blockcode>
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  RuntimeService runtimeService = processEngine.getRuntimeService();
  List<ProcessInstance> list = runtimeService.createProcessInstanceQuery().processDefinitionKey("TimerProcess").list();
  for (Iterator<ProcessInstance> iterator = list.iterator(); iterator.hasNext():smileywink: {
   ProcessInstance instance = (ProcessInstance) iterator.next();
   Execution waitStateExecution = runtimeService.createExecutionQuery().processInstanceId(instance.getId()).activityId("waitTimer").singleResult();
   if (waitStateExecution!=null) {
    runtimeService.signal(waitStateExecution.getId());
   }
  }
</blockcode>