Best Practice to Stop/Abort/Cancel a running workflow

110 views
Skip to first unread message

tzu...@gmail.com

unread,
Oct 26, 2016, 7:43:18 AM10/26/16
to COPPER Engine


Hi
What is the best way to stop/abort/cancel a running workflow.
We want to cancel a workflow in a cooperative way. Meaning the workflow will be notified that it is canceled. If it is waiting it should be interrupted. 

Currently we could not find any API to stop a running workflow in any way.

Thank you

Howie T

unread,
Oct 26, 2016, 10:13:16 PM10/26/16
to COPPER Engine
I believe if it's currently running(meaning not in wait state) it's not copper's job to stop/abort/cancel your workflow. You should try throw a remote exception to your adapter in your working thread, and catch inside copper workflow.

If workflow is in wait state you could do something like this: 


try {
// everything else
} catch (WorkflowTerminationException te) {
// handler for your termination 
} catch (WorkfowCancelException ce){
//handler for your cancel exception
} catch (Exception e) {
//all other unknown exception
} finally {
//clean up
}





Cheers,

Howie

Howie T

unread,
Oct 26, 2016, 11:44:09 PM10/26/16
to COPPER Engine
I think I should add to this answer, in wait state, the workflow should be waiting for a notification, the exceptions (i.e. WorkflowCancelException) should be raised by your notification receivers, and by message from external/internal system.

Michael Austermann

unread,
Oct 27, 2016, 3:38:29 AM10/27/16
to copper...@googlegroups.com
I agree with Howie (as mostly :-))

In addition to his suggestion, here is what I would do to stop a workflow that is waiting:

You know, with copper it is also possible to wait for more than one response/event.
So, assume there is a workflow instance with ID X which is waiting for a response with correlationId C

I would do the wait like this

wait(WaitMode.FIRST, <sometimeout>, X, C);
Response rX = getAndRemoveResponse(X);
Response rC = getAndRemoveResponse(C);
if (rC != null) {
  // everything is fine - process the response and continue;
}
else if (rX != null) {
  // someone told us to abort
  throw new WorkflowCancelException(); // catch this somewhere as described below by Howie
}

So, you can easily abort the workflow instance with ID X, by just sending some response with CorrelationID X.


Hope this helps..

/Michael





Von: "Howie" <cka...@gmail.com>
An: "COPPER Engine" <copper...@googlegroups.com>
Gesendet: Donnerstag, 27. Oktober 2016 05:44:09
Betreff: [COPPER Users] Re: Best Practice to Stop/Abort/Cancel a running workflow

--
You received this message because you are subscribed to the Google Groups "COPPER Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to copper-engin...@googlegroups.com.
To post to this group, send email to copper...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/copper-engine/bc060f86-8a4c-4737-b3e8-ac42ce7e041d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Howie T

unread,
Oct 27, 2016, 3:49:13 AM10/27/16
to COPPER Engine, michael.a...@scoop-software.de
Yeah, it depends on your preference, for me I wanted to move the error handling logic outside of my "generic workflow", but sure that's much simpler to directly code in your specific workflow :)

Basically, understand how to use wait(), getAndRemoveResponse(), getAndRemoveResponses() and engine.notify() is very crucial to the understanding of copper engine!
Reply all
Reply to author
Forward
0 new messages