Workflow Cancelation Behavior

I’m implementing a tempolar project using springboot framework, is there any way to catch the cancelation event for the workflow or activity in the code if i canceled the workflow execution through the webui. Is this approach is valid ?

Yes you can handle cancelation in workflow code (and perform some actions before execution is finally canceled) and in activity code if it heartbeats, see examples here and here.

Note that in second example ActivityFailure would have CanceledFailure as its cause.
Also if cancelation comes in while you have pending child workflows you would need to handle ChildWorkflowFailure which would also include CanceledFailure as cause).
If cancelation comes in while your workflow is for example awaiting an event or a timer (like workflow.sleep), you’d want to handle CanceledFailure directly. So given what your workflow code does you might need to handle these three exceptions and then
run some cleanup in detached cancelation scope if needed.
Also note that if what you do in detached cancelation scope takes long time, it can delay workflow being canceled, but it will get canceled when this cleanup work completes.

1 Like