cancel
Showing results for 
Search instead for 
Did you mean: 

RuntimeService execution query returns empty list

serid
Champ in-the-making
Champ in-the-making
Hi All,

I am completely new to Apache Activiti and doing some basic stuff trying to understand how it all works.
I have a very basic bpmn file consisting only of start, service task and stop.
I have implemented the service task using JavaDelegate.
Using activiti with spring boot.

After starting the process I try to get executions for the process:


List<Execution> executions = runtimeService.createExecutionQuery().list();
List<ProcessInstance> pis = runtimeService.createProcessInstanceQuery().list();
LOGGER.info("Executions: " + executions.size());
LOGGER.info("PIs: " + pis.size());


and am always getting empty lists. Can anybody please explain why is that ?

Thanks,
Adrian
7 REPLIES 7

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Adrian,

is process already finished? (If yes there is no execution active in it)

Regards
Martin

serid
Champ in-the-making
Champ in-the-making
Hi Martin,

No - the process is still running.
I made sure it is by running:

<code>
new Thread("Activiti Thread") {
          
   @Override
   public void run() {
      runtimeService.startProcessInstanceByKey("myRealProcessTest");
   }
          
}.start();
         
synchronized (this) {
   wait(3000);
}

List<Execution> executions = runtimeService.createExecutionQuery().list();
List<ProcessInstance> pis = runtimeService.createProcessInstanceQuery().list();
LOGGER.info("Executions: " + executions.size());
LOGGER.info("PIs: " + pis.size());
</code>

The service task is running for 30 seconds and I am getting every 3 seconds info in logs of its status.

So no - I start the process, wait 3 seconds to make sure that the task starts (which I can see in logs) and then
I query for the executions - gives empty list after which I still get updates from the task.


Thanks,
Adrian

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Adrian,

I can only guess (jUnit test could help a lot: https://forums.activiti.org/content/sticky-how-write-unit-test)
The problem could be that:
1. process starts execution and service task waits for 30s.
2. the db transaction is not committed to the DB - that's why the queries executed from different transactions do not return any execution.

Regards
Martin

warper
Star Contributor
Star Contributor
My moneys on "2. the db transaction is not committed".
Since it looks like synchronous process, it is not commited to DB up to the end.

serid
Champ in-the-making
Champ in-the-making
Hi guys,

Thanks very much for your replies and sorry for delay in replying - went for a short holidays …
Right - it would make sense - it is synchronous process.

It might be slightly now off topic but here is what I try to achieve:

1) I have my own wrapper around JavaDelegate - it's purpose is to implement a progress handling so on my UI when particular activiti (JavaDelegate) is running I get a progress bar which is updated now and then.
2) Of course I don't want to limit process definition to include only JavaDelegates. So I also want to display information about how many
activities there are defined in a process, how many of them have already run (so I can see how many left to run) and what is the current activiti name running.

So far what I have done to achieve it is that I have my own service layer which starts the process and it implements the ActivitiEventListener.
On PROCESS_STARTED I do:

<code>
List<String> completedTasks = new ArrayList<String>();
runtimeService.setVariable(event.getExecutionId(), "completed-tasks", completedTasks);
</code>

and on ACTIVITI_COMPLETED I do:

<code>
List<String> tasks = (List<String>) runtimeService.getVariable(event.getExecutionId(), "completed-tasks");
if (ActivitiActivityEvent.class.isAssignableFrom(event.getClass())) {
   ActivitiActivityEvent activitiEvent = (ActivitiActivityEvent) event;
   tasks.add(activitiEvent.getActivityName());
}
</code>

So here is my problem:

1) The process can be asynchronous so my assumption (have not verified it yet) is that event.getExecutionId() will be different for each activity ?
In that case - is there a way to get the "most parent" id of the process which would be the BPMN execution ID ?
2) A process defined in BPMN file can be set to be synchronous - so it seems I cannot use the execution query as it will be empty …

The bottom line is - how do I get at any point the number of activities in a process with ability to say which ones have already completed ?



Many thanks for your input - much appreciated.

Adrian

warper
Star Contributor
Star Contributor
Hi Adrian!
is there a way to get the "most parent" id of the process which would be the BPMN execution ID
Yes. You can traverse from any execution up by getSuperExecution()/getParent()
AFAIK process_instance_id is execution_id of first/top process execution.

You can do similar search directly in database, but I have no ready selects for it.

The bottom line is - how do I get at any point the number of activities in a process with ability to say which ones have already completed ?
You can write counters into separate data store, not into process variables, and not related to activiti transactions.

serid
Champ in-the-making
Champ in-the-making
Hi,

Thanks for prompt reply.

Indeed it looks like proc_inst_id_ is execution_id_ which is the top process execution (looked at act_hi_actinst table) …
If that is the case than my previous code which uses event.getExecutionId() should work regardless whether the process uses asynchronous activities or not and seems to be the best bet I can think of right now without creating additional DB table to store it. Of course I will need to test it but my testing capabilities are rather thin right now as I still don't have the full picture of the Apache Activiti cause it's all new to me.


Thanks very much for all your help.

Adrian