You might query the current job and check the number of retires left. If it’s zero you throw a BpmnError.