Execute a custom action when a job fails

in a project I am working on, I implemented a custom process instance history APIs, relying on some custom database tables that I upgrade using service tasks inside the process executions. I also implemented a process instances real time monitoring using web sockets. I decided to avoid relying on Camunda history API, since I wanted to have just my own specific database history tables containing all the extra business information that I need that can be queried in a simple way.

I am using extensively asynchronous (before, after or both) service tasks, therefore the tasks are executed by the Job Executor.
I want to update my custom database tables and fire an event using web sockets every time a job related to an asynchronous service task fails. This way, I can update my history tables setting a “JOB FAILED” state and I can notify the UI using web sockets about the job failure.
Is there a way to listen to job failed events using the Java API, or maybe adding some listeners in the process definitions? I had a look at the documentation, but I couldn’t find a simple way to achieve this.

Once I will achieve this, I assume that I can let the user of my application re-submit the job using the POST /job/{id}/execute REST API (or the corresponding Java API), is it correct?

I am OK with the standard Camunda retry policy of 3 times when a job fails and I want to keep it like this.

Moreover, is the approach that I took (with my own custom tables for history) a good approach? Is there a better way to implement this, in your opinion, keeping in mind that I also need real time monitoring using web sockets?

Thanks in advance,

Hi Giorgi,

it is possible to register an incident handler which handles incidents in a customer specific way.

Take a look here: https://docs.camunda.org/manual/7.6/user-guide/process-engine/incidents/.

If a job failes a incident handler for type “failedJob” is triggered. This could be some kind of a composite pattern so that you can register many incident handlers for same type of incident.

On of this handlers could do your custom logic.
One other could be the default handler which persists incident in db.

Does this help?

Best regards,


Hi Markus,
thanks for your reply.

The incident handler would do what I want, but unfortunately I cannot register it.
The method


is not static, therefore I need an instance of the ProcessEngineConfiguration. I am using Camunda 7.4 and JavaEE on Wildfly 8, with the Camunda Wildfly subsystem and importing camunda-ejb-client and camunda-engine-cdi in my webapp.

I am trying in my startup singleton EJB that I use for initialization to access the ProcessEngineConfiguration like this:


but it is null.
How can I access the process process engine configuration instance during the startup phase, please?

Hi Giorgio,

you have to build a process engine plugin to customize the engine. Here is an example of a process engine plugin with a different use case, but it shows how to build the Jboss modules with the help of the smartics maven plugin: https://github.com/camunda/camunda-consulting/tree/master/snippets/extended-serialization

Hope this helps,


Hi Ingo,
thanks a lot for your reply and for the process engine plugin example.
I think I will solve my issue in a different way, modeling the way to handle failed jobs directly in the BPM process, but it’s good to know that with a process engine plugin you can actually do it.