Skip to content

CohortGeneration job left in 'STARTED' state when error is thrown. #2216

@chrisknoll

Description

@chrisknoll

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;
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions