cancel
Showing results for 
Search instead for 
Did you mean: 

Timer Question

bhupendrabjain
Champ in-the-making
Champ in-the-making
I am new to Activiti so forgive me if this is a stupid question

I am creating an encoding workflow so after I send a request to do encoding I need to check the status periodically and based on the status I need to either move to the next step in the workflow or terminate the workflow . How can I achieve this in Activiti . I have been using JBPM where I do the following to achieve the above functionality but not sure how can i do the same in Activiti

<state name="Wait for Callback">
      <timer name="Wait for Callback Action" duedate="15 minutes"
         repeat="10 minute">
         <action
            class='com.mtvi.mediabus.egvtranscode.action.MediaSiloUXStatusTimerAction' />
      </timer>
      <transition to="Download Files" name="Download_Files"></transition>
      <transition to="exception" name="exception"></transition>
   </state>

Can someone help me with this ?
7 REPLIES 7

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

You could use timer intermediate event in the loop
http://www.activiti.org/userguide/#bpmnTimerIntermediateEvent

Regards
Martin

Hi martin , Thanks for the reply . I am already using intermediateCatchEvent but i am not sure how to signal it to the next step in the process after the desired status is received ?

bhupendrabjain
Champ in-the-making
Champ in-the-making
Attaching the bpmn file for reference

Code

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.impl.pvm.PvmTransition;
import org.activiti.engine.impl.pvm.delegate.ActivityBehavior;
import org.activiti.engine.impl.pvm.delegate.ActivityExecution;

import com.mtvi.unicorn.bean.TestBean;

public class CheckStatus implements ActivityBehavior {


public void execute(ActivityExecution execution) throws Exception {
  TestBean ts = (TestBean) execution.getVariable("testBean");
     System.out.println("I am here to check Status:" + ts.getId());
     PvmTransition transition = null;
     try {
       int id = ts.getId();
       if (id > 20) {
       transition = execution.getActivity().findOutgoingTransition("flow6");
       execution.take(transition);
       } else {
       id = id + 10;
       ts.setId(id);
       }
     } catch (Exception e) {
       transition = execution.getActivity().findOutgoingTransition("flow5");
       execution.take(transition);
     }
    
}

I am trying to transition to next node only if the condition is reached but the problem here is this class is called only once . I want this class to be called again and again till the condition is reached and it moves to the next node . Can someone help me with this

trademak
Star Contributor
Star Contributor
The intermediate catch event doesn't fire again if the process instance reached an end state in the first cycle. Is that the case in your example?

Best regards,

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi

bhupendrabjain
Champ in-the-making
Champ in-the-making
Thanks Martin . I am using exclusive gateway and I am able to transition from one task to another based on certain condition

I am still not clear about certain things

1) If I use ReceiveTask  dont I need an external Trigger to take some action ?

2) In timer I want it to repeat checking the status every 1 min for n number of times
I gave the following in my bpm file

<timeCycle>R3/PT1M</timeCycle>

I thought the above expression means repeat 3 time every 1 minutes but I see it is checking status every sec .

martin_grofcik
Confirmed Champ
Confirmed Champ
1) If I use ReceiveTask dont I need an external Trigger to take some action ?
Yes. Trigger signals process execution to continue.

2) In timer I want it to repeat checking the status every 1 min for n number of times
Could you prepare jUnit test for it?
http://forums.activiti.org/content/sticky-how-write-unit-test

Regards
Martin