Expected behavior
If there is a failure during cohort generation, the job should result in FAILED.
Actual behavior
The exception thrown in GenerationJobExecutionListener is ignored by Spring Batch.
Steps to reproduce behavior
This is difficult to reproduce because you need to throw an exception during GenerationJobExecutionListener.findBySourceId.
However, the behavior is described here.
The solution is to wrap the work done in afterJob (which contains the call to findBySourceId) in an exception handler such that the job step is set to failed:
Example code:
public class YourListener implements StepExecutionListener {
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
try {
yourcode ///////
} catch (Exception e) {
//log your error
stepExecution.setStatus(BatchStatus.FAILED);
stepExecution.addFailureException(e);
return ExistStatus.FAILED.addDescription(e);
}
return ExitStatus.COMPLETED;
}
}
Expected behavior
If there is a failure during cohort generation, the job should result in FAILED.
Actual behavior
The exception thrown in GenerationJobExecutionListener is ignored by Spring Batch.
Steps to reproduce behavior
This is difficult to reproduce because you need to throw an exception during
GenerationJobExecutionListener.findBySourceId.However, the behavior is described here.
The solution is to wrap the work done in afterJob (which contains the call to findBySourceId) in an exception handler such that the job step is set to failed:
Example code: