I’m looking for a way to get notified AFTER a user task is completed. Sure I know about “complete” event but with a little debugging it seems that all listeners are executed synchroneously in the same thread as completing is.
My goal is the following: When a user task is completed, my Spring Boot backend notifies my frontend that the list of active user tasks has changed. The frontend then queries the backend which queries TaskService.
In the above scenario I encounter random timing problems because the task is still available when querying the TaskService when the frontend is notified.
I could put the frontend websocket notification and TaskService query in a callable and do busy querying in a separate thread until the task has vanished from the query result, but that’s really ugly imho.
Does anyone know about a sure method to get notified when a task is “really” completed?
Wanted to just point about that officially Camunda 7.13 doesn’t support that version of spring boot. check out this matrix for more information.
So that is true - but the task is only officially complete once it’s been committed to the database. if you wanted to achieve something commits to the DB right after a task is complete you can add an async afteron the user task. That might help
Thanks for your answer. I’ve tried setting async after on the user task, but still the notify is executed synchroneously while CompleteTaskCmd is still executing. See stack below.
BroadcastUserTaskListChanged notifies the websocket (in a different thread) there’s still the “race condition” where the frontend queries the task list too early.
Hi @Ingo_Richtsmeier,
thanks for pointing that out. Surely I could use “take” on the outgoing flow, but in my opinion this has 2 drawbacks:
The model is not easily understandable any more, because no one would expect a listener there
I would have to add it on each and every subsequent sequence flow of a user task, not just using @EventListener(condition = "#taskDelegate.eventName=='complete'") which I do at the moment, letting each user task notify the application to reload the task list.
As for the rollback/completion issue @Niall mentioned: Right, without the async after I can never be sure that the process is not rolled back, but that is no issue here since the only purpose of notification is to reload the task list which would be fine also on rollback.