cancel
Showing results for 
Search instead for 
Did you mean: 

Complete task and get next tasks. Transactions and query sync.

emptyfruit
Champ in-the-making
Champ in-the-making
Hi. I'm using Activiti 5.19
In my code on "logically" completing a task i have some logic of saving data from the form (ui). At the end of the method i call a "task complete" method and then query for all the tasks i have availible next for current user (1 or more). The lines go next to each other:


processEngine.getTaskService().complete(taskId);

List<Task> tasks = processEngine.getTaskService().createTaskQuery()
                .processVariableValueEquals(WfConst.ROOT_EXECUTION_ID, rootExecutionId)
                .active()
                .taskCandidateUser(username)       
                .list();


The issue is that the taskQuery executes faster than
complete(taskId)
method. So result list is not full. Especially this happens when the UserTask ends with a CallActivity (creating a subprocess). So i never get the first task that belongs to this subprocess. But if i wait for some time (1-5 sec) in debugger and query again - the task is there and the list if full. Sometimes the query happens so early, that it is simply empty. What are my options on performing these two actions in one transaction?

6 REPLIES 6

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

you can start transaction outside of the activiti engine and manage roll back/commit by yourself.

regards
Martin

emptyfruit
Champ in-the-making
Champ in-the-making
Thank you for your reply. Can you please point me towards how it can be achieved? Currently in our project we just give Activiti a DataSource and Activiti handles all transactions by itself. We're not using Spring.

jbarrez
Star Contributor
Star Contributor
"The issue is that the taskQuery executes faster than complete(taskId) method. "

Not sure how that can be. By default, everything in Activiti is synchronous.
Do you have async steps that follow after your user task?

emptyfruit
Champ in-the-making
Champ in-the-making
I can provide a bigger excerpt of our code, but as i wrote, these 2 lines go one just right after another. This issue happens mainly  when a callActivity is involved: there is a parallel gateway after a completed task. One flow goes back to the same task, another creates a subprocess.  As a result of the query i want to see both tasks: one of the same process, and the first usertask of the created subprocess. On my local machine the query returns next usertask of the main process, but misses the first usertask of a created subprocess (if queried immediately). On our prod. machine the query returns result list absolutely empty. If i stop in a debugger and execute query manually i can actually see the data being updated in a database: i query first time - empty, wait for a second - query again - full. As a temporary measure we placed a simple wait for 300ms after a <code>.complete()</code> method. That does the trick, but is far from a normal solution.

jbarrez
Star Contributor
Star Contributor
The only situation where I can see that happening is if one of these steps are async.
An example that demonstrates it would certainly help here. The way you describe your process, if executed all sync, it shouldn't/can't happen.

emptyfruit
Champ in-the-making
Champ in-the-making
Thank you very much for your help. Indeed, there is been async="true" on a callActivy. A combination of our mistakes got us thinking that the issue could not be in the scheme.