How to stop Camunda Process if any task fails in a process

I know that for each Task there will be some output at the end of the execution, but there is nothing like Staus (SUCCESS/FAILED) for a task.

In my case, I want to have a Status after the execution of the Task and stop the process if any task fails.

I can see only one option that I generate a status output for each task and then add an XOR gate after the task and exit the process in case of status is FAILED, else proceed to the next task in my process.

But that kind of structure (One XOR gate) I have to add for each task.
Any other way which can short-circuit the process at any Task with some setting?

Hi @Himanshu_Singh,

in a service task implemented with a java delegate, mark the task with “Asynchonous Before” and just throw a RuntimeException.

In an External Service Task, call externalTaskService.handleFailure() in your handler inside the worker.

In both case the process instance stops and you will see an incident in the Cockpit: Failed Jobs | docs.camunda.org

Hope this helps, Ingo

3 Likes

And if you want to handle it explicitly in the process, you could add an event sub process with an error start event (interrupting) - this should be mapped to a BPMN error that you throw from the task as a BpmnError - then some handling task(s), then an end event. That will actually complete the process, which will not allow you to recover from within the process, which is what Ingo’s solution does allow you to do.