cancel
Showing results for 
Search instead for 
Did you mean: 

How to track the progress of a workflow

afshad
Champ in-the-making
Champ in-the-making
How do I programatically track the progress of a workflow?
How can I query activiti to find out which task it is currently executing?

Currently this is how I execute a BPMN 2.0 workflow:
        ProcessEngineConfiguration processEngineConfiguration =
                StandaloneInMemProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
        try {
            processEngineConfiguration.setClassLoader(Thread.currentThread().getContextClassLoader());
        } finally {
        }
        ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        RuntimeService runtimeService = processEngine.getRuntimeService();
        try {
            repositoryService.createDeployment()
                    .addInputStream("BPMN.xml", new FileInputStream("BPMN.xml"))
                    .deploy();
            ProcessInstance proc = runtimeService.startProcessInstanceByKey(BPMNCreator.INSTANCE.getWorkflowProcessID());
            if(proc!=null) {
                JOptionPane.showMessageDialog(activeWindow, "Workflow Execution Complete.");
            }
        } catch (FileNotFoundException e1) {
            _logger.log(Level.WARNING, "Batch Processing - Error Loading BPMN xml file", e1);
        } finally {
            ProcessEngines.destroy();
            FileAndGUIUtils.setWaitCursor(activeWindow, false);
        }
4 REPLIES 4

trademak
Star Contributor
Star Contributor
Hi,

You can use the getActiveActivityIds method on the RuntimeService to get the active activities of a specific process instance.

Best regards,

afshad
Champ in-the-making
Champ in-the-making
Hi,

You can use the getActiveActivityIds method on the RuntimeService to get the active activities of a specific process instance.

Best regards,

Thanks however…
I cannot use this method since the call to runtimeService.startProcessInstanceByKey("MyProcessId")
blocks till the whole workflow is executed. So I suppose I should be starting the process instance asynchronously? How would I do that.

Also What is the parameter for getActiveActivityIds(String) ? Is it the same process id as above?
Should I be calling this method in some kind of a loop to keep checking which task is being executed currently?

Thanks

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
1:make te first node async… (see the docs)
2: make a small testcase and you know it…  Smiley Wink

afshad
Champ in-the-making
Champ in-the-making
Thanks Ronald. I made the first and second node async = true and exclusive = false. However now whenever I call getActiveActivitiIds() it returns me the first and second service task names and doesnt seem to quit. After debugging it seems that the execute method of the delegates is never called using asynch.

            ProcessInstance proc = runtimeService.startProcessInstanceByKey(BPMNCreator.INSTANCE.getWorkflowProcessID());
            while(runtimeService.getActiveActivityIds(proc.getId()).size() > 0) {
                List<String> activeActivityIds = runtimeService.getActiveActivityIds(proc.getId());
                for(String str : activeActivityIds) {
                    System.out.println("Currently executing: "+str);
                }
                Thread.sleep(100);
            }
The xml flow:
<parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="parallelgateway1"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="parallelgateway1" targetRef="serviceTask1"></sequenceFlow>
    <sequenceFlow id="flow3" name="" sourceRef="parallelgateway1" targetRef="serviceTask2"></sequenceFlow>
    <parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway>
    <sequenceFlow id="flow4" name="" sourceRef="serviceTask1" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow5" name="" sourceRef="serviceTask2" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow6" name="" sourceRef="parallelgateway2" targetRef="serviceTask3"></sequenceFlow>

<sequenceFlow id="flow7" sourceRef="serviceTask3" targetRef="endevent1"/>
<endEvent id="endevent1" name="End"/>

The loop above never stops and just prints the first and second service Task ids but never actually executes them.  I expect it to print all the service task ids and then break.
It works fine when i dont use a parallel gate way or async = true and have all three service tasks sequential order.
Whats could be going wrong? Why isnt it starting the tasks?

Thanks