temporalio / sdk-java

Temporal Java SDK
https://temporal.io
Apache License 2.0
208 stars 141 forks source link

Run Saga compensations in a disconnected scope #305

Open mfateev opened 3 years ago

mfateev commented 3 years ago

Is your feature request related to a problem? Please describe. Currently Saga.compensate is called in the current cancellation scope. It means that in the case of cancellation the compensations are not going to run. So it requires that compensate is called in the detached cancellation scope. But our sample does not do it.

Describe the solution you'd like By default execute compensation actions in a disconnected cancellation scope. Add Saga.Option to disable this behavior. Change bookingsaga sample to catch TemporalFailure to support cancellation scenarios.

ShubhSingh commented 3 years ago

hi @mfateev, is this issue still open? I tried running booking saga and when exception occurs during bookFlight compensations run as shown below.

cancelling car reservation '953c8762-fc18-4e8a-8a2b-8fe468d0381e' for 'trip2' cancelling hotel reservation '0c7428dd-5357-480c-845d-1c558d3e20d4' for 'trip2'

I didn't understand current and disconnected cancellation scope, does it mean that instead of exception if user deliberately cancels the flight after successful booking then compensations need to run? I might be wrong here so please excuse me.

I checked Saga.Options to disable behavior but there's only 2 configs available as of now: parallelCompensation and continueWithError