cancel
Showing results for 
Search instead for 
Did you mean: 

Timer in standalone application

santoshpatel
Champ in-the-making
Champ in-the-making
Hi,

We are trying to create a standalone application in Java using Activiti APIs. We have been trying to add timer to execute a certain flow after the given time-out. But this is not working as per the expectation. Below is the sample code.

  public static void main (String[] args) {
       ProcessEngine processEngine=ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration().buildProcessEngine();
      
        RepositoryService repositoryService = processEngine.getRepositoryService();
        repositoryService.createDeployment().addClasspathResource("diagrams/demo2.bpmn").deploy();
        RuntimeService runtimeService = processEngine.getRuntimeService();
       ProcessInstance pi = runtimeService.startProcessInstanceByKey("escalationExample");
   
       // There should be one task, with a timer : first line support
       TaskService taskService = processEngine.getTaskService();
       Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
       System.out.println("First line support = " + task.getName());
   
       // Manually execute the job
       ManagementService managementService = processEngine.getManagementService();
       Job timer = managementService.createJobQuery().singleResult();
       managementService.executeJob(timer.getId());

   
       // The timer has fired, and the second task (secondlinesupport) now exists
       task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
       System.out.println("Handle escalated issue = " + task.getName());
  }

We are expecting "escalated issue task" i.e. "secondlinessupport" should be executed after the time-out of 5 min. What is wrong with the code?
Is there any way to handle the timer event and how?
3 REPLIES 3

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi

Is there any way to handle the timer event and how?

Your example is similar to: org.activiti.examples.bpmn.event.timer.BoundaryTimerEventTestHave a look on the org.activiti.engine.test.bpmn.event.timer.BoundaryTimerEventTest in the activiti source.

Regards
Martin

santoshpatel
Champ in-the-making
Champ in-the-making
Thanks, Martin. I have couple of questions on the overall timer event and email task. I am unable to find any satisfactory documentation on these topics.
1. The reference source code you pointed out is the junit test. The standalone application that I have is pretty similar but, still it doesnt work. Is it something to do with the junit framework? I am basically expecting an asynchronous call (kind of callbacks that we write in C++ on timeout). Does activiti provide that?
2. All the samples are JUnit samples. Is it not recommended to have a standalone workflow application using the APIs? We are looking forward the integration of Activiti into our existing product where there is NO user intervention. For example, we will not be providing any forms to get input from the users for any user tasks. We will do that programmatically.
3. Based on the above our product integration requirements, we are also not able to use email task. I was expecting that the API will provide me set and get variables for TO, From, Subject etc. etc. if the task is email task. What I understand is we will have to write our own code to send the emails to intended user, is that correct?

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Santosh,

Ad 1)
Is it something to do with the junit framework?
No
Does activiti provide that?
I am not sure what you are looking for.

Ad 2)
Is it not recommended to have a standalone workflow application using the APIs?
Stand alone apps are quite common (we use them too)

Ad 3)
What I understand is we will have to write our own code to send the emails to intended user, is that correct?
No that's not correct. Activiti mail sending task is the simple one, but is completely working.
(e.g. org.activiti.examples.bpmn.mail.EmailSendTaskTest)

What I would propose:
create stand alone project on github and show the issue there.

Regards
Martin