The docs here Cancel and Compensation Events | docs.camunda.org include a diagram showing use of compensation events that doesn’t work (because the “compensation event is not propagated to the subprocess”). But what is the right way to model that scenario? (Maybe the docs could be updated with a “here is how you should do it” diagram?)
My own use case seems pretty simple but it is hard to figure out how it should be done. I have a process that contains one subprocess. The activities in the subprocess add compensation handlers as they complete. If a “cancel” message arrives before the subprocess completes normally, I want to run the compensation handlers. What is a good way to set this up?
I completely agree, we should maybe have better illustrations about the way to achieve this - I’ll pass this along to the docs team
In the meantime would you mind uploading the model you’ve made already and i can consider how to help you with it?
This shows two different approaches, one with cancel as a boundary event and one with cancel as an event subprocess. (Obviously we didn’t try both at the same time)
The aim is to have the compensation handlers run whenever the cancel message is received. And that includes if the subprocess is restarted by the “amount changed” message.
Can you upload the BPMN model itself so that i can look into editing it
Can you give me some more details about the “amount changed” Message?
I’m interested as to why it would need to cancel the subprocess and start it again - If the change is just to a variable would it be possible just to maintain the scope and simply catch the the message as a non-interrupting message that just changes some variable(s)?
I made this little thing as an alternative, it just kind of boils down the functionality a bit.
That is a boiled down BPMN (as I can’t share the original). In reality, there are 15-20 elements in the subprocess (various kinds of approval), with both service and user tasks, and a second kind of compensation handler. When the amount changes, the whole subprocess has to be restarted. Restarting does remember some state because variables are held at the process instance level. I can’t really see how it can be anything but interrupting as it needs to completely reset the flow back to the start.
Thanks for the alternative. I can see how that would work because there is no subprocess, but I don’t think it helps me.
Would the original BPMN have worked if there wasn’t an “amount changed” message? ie. if you have a boundary message event on a subprocess, do the compensation handlers get added?
I suspect I can achieve my goal by not using compensation in the BPMN, as the variables contain enough info. That doesn’t seem desirable from a documentation perspective though.
Hi @bobottawa @Niels_Hufschmidt ,
Are you able to solve the problem?
I have similar use case where process is already started and completed some activities. In Flight one of the process variable is updated by external source using rest API (e.g. amount ). We might need to do/undo/redo for this change. How to handle these change gracefully is my question?
Perhaps start a new topic about this with more details about your problem and adding your bpmn model.
Also maybe explain why compensation events won’t work for you.
Hi @Niall , have just created Camunda Compensation.
Whenever you get time, please have a look.