Very Imp : How to persist variables in case of Service Task Exception

Hi,

Can someone plz reply ASAP if there is a way to persist variables set using execution.setVariables in case service task throws an exception.
The use case is 4 service tasks in a row. 4th task throws an exception. Process rolls back to last user task (deleting success response from 1st 3 service tasks). Now when user re-submits, first 3 service tasks are again called. Problem is we can call one of the first 3 services only once after success is returned, after that it will send us error response and if we receive error we throw exceptions from service task. Now user is stuck because we are getting error response from that service and user cannot move forward.
But if somehow i can persist the response in variables, i can use that to re run the logic and not hit the api and user can just move forward.

Thank you,
Arpit

We have similar need to solve in near future, we think this is something we can achieve using event handlers.

Probably by having a customer event listener that extednds AbstractFlowableEngineEventListener which seem to have getExecution() method?

Depending on your requirement, you can mark your service tasks as asynchronous.
This will commit the transaction, so that if you get an exception, it will not roll back.
In this case you need to handle the exception case so that your process does not stall.

Or you can do compensation. Have a look at the documentation.
Using this you can cause the other service tasks to roll back in a controlled way so that, when the user tries a second time, all the service tasks are ready to process the transaction instead of giving you an error.

Anyone found a solution?

1 Like