cancel
Showing results for 
Search instead for 
Did you mean: 

runtime service does not return running process

flavio_donze
Champ in-the-making
Champ in-the-making
Hello

I have a process which in certain cases does not require any userTask.
In one of the serviceTasks I'm accessing the Activiy RuntimeService to receive all the running processes.

for (ProcessInstance processInstance : runtimeService.createProcessInstanceQuery().list()) {
   System.out.println("RUNNING>: " + processInstance.getId());
}
Well the current running process is not in the query result.
Is this a normal behavior or could this be because of my Spring JPA environment?
As soon as the process comes upon a userTask and afterwards to the mentioned serviceTask, the current process is listed. Probably because it is then written into the database.  

Appreciate any hint or maybe workaround!

greets
Flavio
4 REPLIES 4

trademak
Star Contributor
Star Contributor
Hi,

When you've started the process instance with the runtime service and received a ProcessInstance back the instance is written to the database.
So at that point you should also be able to retrieve the running instance with the process instance query capabilities.
If this is not working, please include the process XML and the Java code you are using.

Best regards,

flavio_donze
Champ in-the-making
Champ in-the-making
Hey trademak

Thanks for your quick reply!

Yes the following code does list the running process.

ProcessInstance instance = runtimeService.startProcessInstanceByKey(processKey, variables);
for (ProcessInstance in : runtimeService.createProcessInstanceQuery().list()) {
System.out.println("RUNNING>: " + in.getId() + " " + in.getProcessDefinitionId());
}

The problem I have is that my serviceTask is executed before startProcessInstanceByKey() returns the ProcessInstance, hence nothing is listed.
Maybe there is a way to force activity to write?

greets
Flavio

trademak
Star Contributor
Star Contributor
Hi,

Okay right. In Activiti 5.8 we'll introduce asynchronous continuations to solve this.
For now you can add a receive task before the service task and signal the process instance.
The receive task will make sure the process instance is persisted.

Best regards,

flavio_donze
Champ in-the-making
Champ in-the-making
Thanks a lot! Got it to work with the "receive task".

Is the release date known for 5.8? Could not find it on the website.

greets
Flavio