Compensation events inside subprocesses

852 views
Skip to first unread message

joern.h...@zalando.de

unread,
Jan 26, 2016, 10:04:50 AM1/26/16
to camunda BPM users
I have a subprocess containing multiple tasks, the first of which has a compensation boundary event attached. The documentation at https://docs.camunda.org/manual/7.4/reference/bpmn20/events/cancel-and-compensation-events/#intermediate-throwing-compensation-event says about this

> If compensation is thrown within a scope which contains a subprocess and the subprocess contains activities with compensation handlers, compensation is only propagated to the subprocess if it has completed successfully when compensation is thrown. If some of the activities nested inside the subprocess have completed and have attached compensation handlers, the compensation handlers are not executed if the subprocess containing these activities is not completed yet.

As a workaround I could set a process variable in the first task and do the compensation explicitly when handling errors.

Is there maybe a cleaner way and is this really the way that compensation inside subprocesses should behave?

If I wanted the current behaviour I think I could just attach the compensation to the subprocess itself.

Regards,
Jörn Horstmann

Philipp Ossler

unread,
Jan 28, 2016, 4:29:53 AM1/28/16
to camunda BPM users, joern.h...@zalando.de
Hi Jörn,

I don't understand your issue exactly. Can you please provide a BPMN that shows your use case.

Assuming that your process looks like this:

















In case the task b is active, if the task c throws an error then an compensation event is thrown which can not be catch from the compensation handler on task a because the subprocess is not completed yet. 
Generally, BPMN defined comensation is a way:
  • compensation will only trigger activities "at the same level of sub process" (and then be propagated inside in case these are subprocesses themselves)
  • you can only compensate activities which are completed. If an Activity is still active, it cannot be compensated but rather needs to be canceled. 

So the current behavior should be right.

However, why is the throwing compensation event not inside the subprocess?

Note that your approach to attach a compensation handler on the subprocess may not working since the compensation event is thrown on an upper scope.

Greetings,
Philipp







 


joern.h...@zalando.de

unread,
Jan 28, 2016, 10:25:32 AM1/28/16
to camunda BPM users, joern.h...@zalando.de
Hi Phillip,

You are right, the process is a bit difficult to explain. I created a model and unit test to show the behaviour I would have liked:

https://github.com/jhorstmann/camunda-engine-unittest/blob/compensation-in-subprocess/src/test/resources/testProcess.png

https://github.com/jhorstmann/camunda-engine-unittest/blob/compensation-in-subprocess/src/test/java/org/camunda/bpm/unittest/SimpleTestCase.java#L76

In the real process there are some more tasks inside the subprocess, and the process should be cancelable using a message correlation while theses tasks are executing.

> compensation will only trigger activities "at the same level of sub process" (and then be propagated inside in case these are subprocesses themselves)

This would explain the behaviour I'm seeing, since I'm triggering compensation outside the subprocess.

I will try doing the same using an event subprocess.

Thanks,
Jörn


Am Donnerstag, 28. Januar 2016 10:29:53 UTC+1 schrieb Philipp Ossler:
> Hi Jörn,
>
>
> I don't understand your issue exactly. Can you please provide a BPMN that shows your use case.
>
>
> Assuming that your process looks like this:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> In case the task b is active, if the task c throws an error then an compensation event is thrown which can not be catch from the compensation handler on task a because the subprocess is not completed yet. Generally, BPMN defined comensation is a way:compensation will only trigger activities "at the same level of sub process" (and then be propagated inside in case these are subprocesses themselves)you can only compensate activities which are completed. If an Activity is still active, it cannot be compensated but rather needs to be canceled. 

joern.h...@zalando.de

unread,
Jan 28, 2016, 10:47:53 AM1/28/16
to camunda BPM users, joern.h...@zalando.de
So using an event subprocess it works, thanks again for your explanation regarding triggering compensation on the same level.

This is how it looks like: https://github.com/jhorstmann/camunda-engine-unittest/blob/compensation-in-subprocess-with-event-subprocess/src/test/resources/testProcess.png

Regards,
Jörn

Philipp Ossler

unread,
Jan 29, 2016, 4:18:28 AM1/29/16
to camunda BPM users, joern.h...@zalando.de
Hi Jörn,

just for clarification, your first approach don't work because the subprocess was not successfully completed. When the boundary event is triggered then the subprocess is canceled. So it can't be compensated.

If the subprocess completed successfully and a compensation event is thrown then the compensation handlers of subprocess (e.g. compensate task) would be triggered.

However, your second approach looks good.

Greetings,
Philipp

Reply all
Reply to author
Forward
0 new messages