Repeat or don't repeat an activity depending on the exception

Hello,

if I understand the spring-zeebe library correctly, I can fail a job by just throwing an exception in the job worker. In this case, the job will be repeated according to the setting in the process model. If there are no retries left, the activity will be marked as failed.

My question is: Is it possible to tell somehow that no retries should be made and the activity should be immediately marked as failed?

I need this in order to differentiate the situations where a retry might lead to a success from the situations where there is no chance for a retry to succeed and hence no unneeded retries should be made.

Note that I’m not talking about BPMN errors. I don’t want to fail the whole process instance but just one activity.

Thank you for any hints.

Hi @fml2

You can set the retries to zero if no retries should be attempted.

zeebeClient.newFailCommand(job.getKey())
           .retries(0)  // No retries
           .errorMessage("Job failed and will not be retried.")
           .send()
           .join();
1 Like

Thank you @hassang! My expectation was that I could just throw an exception from my JobWorker without having to cope with the zeebe API. And that the framework somehow catches the exception and decides whether the retry number should be immediately set to 0.

But I now see that the framework can’t do this. This would be a sensible enhancement IMO.

Hi @fml2

Using spring zeebe, you need to disable autoComplete

https://docs.camunda.io/docs/apis-tools/spring-zeebe-sdk/configuration/#programmatically-completing-jobs