Triggering incident immediately from Java Delegate

Greets! I’ve got a very simple process which consists of a single service task with custom retry configuration (infinite number of retries with 1 minute intervals) and async before flag:

@Slf4j
@Component
public class PrintHelloDelegate implements JavaDelegate {

  @Override
  public void execute(DelegateExecution execution) throws Exception {
    log.info("Hello!");
    throw new RuntimeException();
  }
}


It’s all good and works as expected, the next thing I’m trying to achieve is to cause an incident under certain circumstances. Say I have a particular case when retrying is useless and I just want to trigger an incident and see a red token on that task in Cockpit with no further retries.

I’ve tried setting job retries to zero before throwing an exception:

Job currentJob = managementService.createJobQuery()
    .processInstanceId(execution.getProcessInstanceId())
    .singleResult();
managementService.setJobRetries(currentJob.getId(), 0);

// proceed to throw an exception

But it seems to completely ignore job retries set to 0 and keeps retrying starting with Integer.MAX_VALUE retries left

I also played around org.camunda.bpm.engine.RuntimeService#createIncident, which just gives me an instance of org.camunda.bpm.engine.runtime.Incident class and still nothing happens:

Incident failedJob = execution.getProcessEngineServices()
    .getRuntimeService()
    .createIncident("failedJob", execution.getProcessInstanceId(), execution.getId(), "some message");

I feel like I am probably missing something, any advice is appreciated. I am using Camunda 7.19 in Spring Boot environment, no fancy configs, just a Get started with Camunda and the Spring Boot | docs.camunda.org project.

Just for giggles (and not saying this will work…)
What happens if you try setting the retries to 1, and then throw the Exception?

I know that seems counter-intuitive, but uint.MAX = signedInt(-1) … So it’s possible that Camunda is decrementing the retries before checking if it should throw an incident.

I am terribly sorry for the late reply mate, had basically no time to return to this topic and re-check the solution with modified retries left counter. I just did, but to no avail: the behaviour is still the same :frowning: I wonder why don’t they have a transparent mechanism to raise incident at any point.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.