Retrying incidents for failedjobs and failedExternalTask using service

Hi , I have created an api for retrying the stuck incidents using the incident id , this the the api-
@RequestMapping(method = RequestMethod.POST, value = “/resolveIncident/{incidentId}”)
@ApiOperation(“Retry stuck Activity”)
@ApiResponses({ @ApiResponse(code = 400, message = “Bad request data”, response = Level3Response.class),
@ApiResponse(code = 404, message = “Resource not found”, response = Level3Response.class),
@ApiResponse(code = 409, message = “Resource not in correct state”, response = Level3Response.class),
@ApiResponse(code = 500, message = “Server side error”, response = Level3Response.class) })
@Timed
public ResponseEntity resolveStuckActivityIncident(@PathVariable(value = “incidentId”) String incidentId)
throws Exception {

	final boolean result = processOperations.resolveStuckActivityIncident(incidentId);
	return ResponseEntity.ok(new Boolean(result));
	
}

now this api is calling the method -

public boolean resolveStuckActivityIncident(String incidentId) {
LOGGER.info(“Attempting to resolve incident with ID: {}”, incidentId);

    try {
        LOGGER.debug("Calling runtimeService.resolveIncident for incident ID: {}", incidentId);
        this.runtimeService.resolveIncident(incidentId);
        LOGGER.info("Successfully resolved incident with ID: {}", incidentId);
    } catch (Exception ex) {
        LOGGER.error("Error while resolving Camunda incident with ID: {}: {}", incidentId, ex.getMessage(), ex);
        return false;
    }

    LOGGER.info("Exiting resolveStuckActivityIncident for incident ID: {}", incidentId);
    return true;
}

When I try to the hit the api , its giving me a false return value always but when i tried resolving the incidents manually in the cockpit , its getting resolved, but this i want to do with service . please suggest how can I do this.

What’s in the exception?

I am getting BadUserRequestException

public Void execute(CommandContext commandContext) {
final Incident incident = commandContext.getIncidentManager().findIncidentById(incidentId);

EnsureUtil.ensureNotNull(NotFoundException.class, "Cannot find an incident with id '" + incidentId + "'",
    "incident", incident);

if (incident.getIncidentType().equals("failedJob") || incident.getIncidentType().equals("failedExternalTask")) {
  throw new BadUserRequestException("Cannot resolve an incident of type " + incident.getIncidentType());
}

EnsureUtil.ensureNotNull(BadUserRequestException.class, "", "executionId", incident.getExecutionId());
ExecutionEntity execution = commandContext.getExecutionManager().findExecutionById(incident.getExecutionId());

EnsureUtil.ensureNotNull(BadUserRequestException.class,
    "Cannot find an execution for an incident with id '" + incidentId + "'", "execution", execution);

for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
  checker.checkUpdateProcessInstance(execution);
}

commandContext.getOperationLogManager().logProcessInstanceOperation(UserOperationLogEntry.OPERATION_TYPE_RESOLVE, execution.getProcessInstanceId(), 
    execution.getProcessDefinitionId(), null, Collections.singletonList(new PropertyChange("incidentId", null, incidentId)));

execution.resolveIncident(incidentId);
return null;

}

If you look at what the UI is doing, it is adding another retry to the external task.

It is a bit of a palava, to do, but from the incident, you can get the processInstanceId (sadly you cannot get the task id … don’t know why) and query the task by processInstanceId. Then you can use the ExternalTaskService to add 1 or more retries.

Hi I didn’t get you , can you be more clear on this .

If you open the browser dev tools and look at the http calls the UI is making, you can see it is calling the an api to set the retry for that task (which was zero) to 1.

You can use the same api. You just need to get the task id.

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