반응형
목차
아래 포스팅에서 이어진 내용입니다.
사용자 정의 ExitStatus 설정하는 방법 예제
jobTestConfig 🙂
package com.dev.lsy.springbatchremind.batch;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Slf4j
@RequiredArgsConstructor
@Configuration
public class JobTestConfig {
private final JobBuilderFactory jobBuilderFactory;
private final StepBuilderFactory stepBuilderFactory;
@Bean
//job
public Job job1() {
return jobBuilderFactory.get("job1")
//jobParameter 자동 증감
.incrementer(new RunIdIncrementer())
.start(step1())
.next(step2())
.build();
}
@Bean
//step
public Step step1() {
return stepBuilderFactory.get("step1")
.tasklet(((contribution, chunkContext) -> {
log.info("=======================================");
log.info("여기는 step1입니다.");
log.info("=======================================");
return RepeatStatus.FINISHED;
}))
.build();
}
@Bean
//step
public Step step2() {
return stepBuilderFactory.get("step2")
.tasklet(((contribution, chunkContext) -> {
log.info("=======================================");
log.info("여기는 step2입니다.");
log.info("=======================================");
return RepeatStatus.FINISHED;
}))
//step listener 추가
.listener(new statusCheckingListener())
.build();
}
}
statusCheckingListener 😎
package com.dev.lsy.springbatchremind.batch;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
//StepExecutionListener의 구현체 클래스
public class statusCheckingListener implements StepExecutionListener {
@Override
public void beforeStep(StepExecution stepExecution) {
}
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
//새로운 ExitStatus 정의 후 return
if (!stepExecution.getExitStatus().getExitCode().equals("FAILED")) {
return new ExitStatus("GOOD");
}
return null;
}
}
개인 스터디 기록을 메모하는 공간이라 틀린점이 있을 수 있습니다.
틀린 점 있을 경우 댓글 부탁드립니다.
reference: https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-%EB%B0%B0%EC%B9%98
다음 내용
반응형
'IT > development' 카테고리의 다른 글
[springBoot] spring batch multiThread process(feat. taskExecutor) (52) | 2023.11.22 |
---|---|
[springBoot] spring batch job/stepExecutionListener (51) | 2023.11.18 |
[springBoot] spring batch flowJob (feat.simpleFlow) (55) | 2023.11.18 |
[springBoot] spring batch jsonFileItemWriter (55) | 2023.11.18 |
[springBoot] spring batch FlatFileItemWriter (55) | 2023.11.16 |