Interrupting long running service tasks

Hi there,

I came across a problem, where I have a long running service task, that can be interrupted by an event.
Can I get notified about the Interruption in my code during execution of my service task in order to handle the interruption properly?
What if I want to decide, whether I want to do a rollback of the work that has already been done until the interruption or just stop working at that exact point when the interruption occurs?

Thanks for your time.

Hi @sebipi,

in general, if you use an interrupting boundary event on the task then the task is aborted and you have no chance to handle the interruption.

What do you do in the long running task and how to you execute it?

The recommended way is to use an asynchronous service invocation. The service task just call the service that do the work and wait till the service continue the task via signal.

In this case, your service may have additional methods to abort or stop the execution which can be invoked when an event is occurred.

Does this help you?

Greetings,
Philipp

Hi @Philipp_Ossler,

Thank you for your fast reply.

In my case, the long running task is a migration task, that collects and manipulates data from multiple systems and potentially takes several minutes.
This task can be interrupted at any time. In this case, i want to prevent an inconsistent state across the involved systems.

In order to guarantee a consistent state, i need my service to be notified of the abortion and not just killed without any notification.

To me, it feels quite unsatisfying, to know that a task can be killed without any way to handle it and provide some kind of “save shutdown”.

Greetings,
Sebastian

Hi Sebastian,

I assume that you execute the migration synchronous in the service task. Right?
This is not recommended since it blocks the process engine. Instead, you can use asynchronous service invocation like I described it. It can also solve your problem with the interruption.

So your process can look like:

Greetings,
Philipp

Hi Philipp,

I’ll implement your last suggestion and maybe come back if it doesn’t work as i need it.
Thank you for your help for now!

Greetings,
Sebastian