Open 0JUUU opened 2 years ago
StepBuilder
를 생성하는 팩토리 클래스 ➡️ get(String name)
메서드 제공
StartLimitExceededException
발생Integer.MAX_VALUE
@Bean
public Step step2() {
return stepBuilderFactory.get("step2")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
System.out.println("stepContribution = " + stepContribution + ", chunkContext = " + chunkContext);
throw new RuntimeException("");
// return RepeatStatus.FINISHED;
}
})
.startLimit(3)
.build();
}
StartLimitExceededException
에러 발생allowStartComplete(true)
설정 : 성공한 Step도 재 실행 ⭕️// 실습코드
@RequiredArgsConstructor
@Configuration
public class JobStepConfiguration {
private final JobBuilderFactory jobBuilderFactory;
private final StepBuilderFactory stepBuilderFactory;
@Bean
public Job parentJob() {
return this.jobBuilderFactory.get("parentJob")
.start(jobStep(null))
.next(step2())
.build();
}
@Bean
public Step jobStep(JobLauncher jobLauncher) {
return stepBuilderFactory.get("jobStep")
.job(childJob())
.launcher(jobLauncher)
.parametersExtractor(jobParametersExtractor())
.listener(new StepExecutionListener() {
@Override
public void beforeStep(StepExecution stepExecution) {
stepExecution.getExecutionContext().putString("name", "user1");
}
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
return null;
}
})
.build();
}
@Bean
public Job childJob() {
return this.jobBuilderFactory.get("childJob")
.start(step1())
.build();
}
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
return RepeatStatus.FINISHED;
}
})
.build();
}
@Bean
public Step step2() {
return stepBuilderFactory.get("step2")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
return RepeatStatus.FINISHED;
}
})
.build();
}
private DefaultJobParametersExtractor jobParametersExtractor() {
DefaultJobParametersExtractor extractor = new DefaultJobParametersExtractor();
extractor.setKeys(new String[]{"name"});
return extractor;
}
}
JobParametersExtractor
로 설정한 것