I try to close a Failed Job Type Incident Manually and I use the codes below to skip the activity and the process manage to skip the failed task and proceed to complete.
In my case, my failed job is a service task which call a subprocess.
The solution is below:
ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstanceId);
// get the Transition instance of the subprocess
String childTransitionInstanceId = activityInstance.getChildTransitionInstances()[0].getId();
// skip the task
runtimeService.createProcessInstanceModification(processInstanceId)
.startAfterActivity(activityId)
.cancelTransitionInstance(childTransitionInstanceId) // << we need to cancel TransitionInstance here
.execute(false, false);
Compared to activity instances, transition instances do not represent active activities but activities that are about to be entered or about to be left. This is the case when jobs for asynchronous continuations exist but have not been executed yet. For an activity instance, child transition instances can be retrieved with the method getChildTransitionInstances and the API for transition instances is similar to that for activity instances.
Hence, the reason is the activity in the subprocess is not active anymore and it is move the Transition state , so it is a Transition Instance instead of a activity instance. Therefore, we need to cancel the related Transition Instance. After we cancel the transition state, the related incident would be resolved as well.
Edit: The reason we use this approach because we cannot resolve failed job using the API RuntimeService#resolveIncident from the doc Incidents | docs.camunda.org