cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping a Process Workflow

erwincc
Champ in-the-making
Champ in-the-making
I am using Activiti Engine to execute a series of Java processes (including web services) using JavaDelegate instances. However, I have a Use Case where if one of these processes fail - let's say the 3rd of 5 processes, throws a Fatal exception (maybe due to unavailability of data or connectivity issues), I want to cancel or stop the workflow.  I saw a in previous posts that it can be done using BPMN boundary event but this would mean that each of my Service Task would need to be wired to that event. If I have 20 processes I need to do that for each of them.

Is there a way to totally stop/cancel the execution of the workflow within an instance of the JavaDelegate?

Thanks in advance.
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
Within a java-delegate, it's not possible to "explicitly" end the process, rather, you can throw a BpmnError() and have a catching error-boundary event. This error-cathicng event can lead to an end-event, effectively ending the process. You can add all of your process-steps in a sub-process (separate scope) which you can attach the boundary event to. This way, you only have ONE catching boundary-error-event for your process, and you can throw an error from any part of the process.

cundurs
Champ in-the-making
Champ in-the-making
Hello!

Is it possible programmatically set next activity for execution to some other activity from workflow definition? I mean, when is need to stop process instance, instead of using error-boundary events connected to the end event, just jump to the end activity? In book "Activiti in Action", there is listing 7.1, where execution path is chosen from service task. In example, there is selected one transition from 2 on current execution available. It would be great, if it would possible select in similar way the next activity using id or any transition existing on process definition. 

I known, this is very bad design. We are evaluating possibility to change currently used engine to Activiti without re-drawing all workflows, but instead find the closest behavior to make migration simple as possible and skip manual work. In current engine every workflow definition contains optional activity, which is not connected to any other. Process instance checks some variable, if variable has some specific value like flag "stop", using engine APIs next activity is set optional activity. Since this activity is not connected to anything, process finishes.  I read thread "Adding a dynamic step while the instance is in flight",  where is very similar requirement, but in our case we do not need to execute anything - jump to the end would be enough. 

Thanks for the advice - error-boundary event , of course, is the right solution. 

jbarrez
Star Contributor
Star Contributor
Yes, you can do it (but indeed, not good design). You will need to use the ActivityBehavior interface, not the JavaDelegate.
In that interface, you can pretty do whatever you please (with all the dangers that come attached to it)

cundurs
Champ in-the-making
Champ in-the-making
Thank You,  Joram.