inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 배치

JobExecutionListener / StepExecutionListener

step endtime 질문

517

최준성

작성한 질문수 30

0

안녕하세요. 

간단하게 질문이 있습니다.

StepExecutionListener의 afterStep 메서드에서 StepExecution의 endTime을 가져왔는데 null로 찍히는데 왜 null로 찍히는 건가요??

afterStep이니까 Step이 끝난 상태에서 동작하기 때문에 endTime이 찍힐 줄 알았는데 null이 찍혀서 궁금하여 질문드립니다.

spring-boot spring-batch

답변 1

0

정수원

endTime 은 StepExecutionListener 이후에 값이 저장되고 있습니다.

finally {

try {
// Update the step execution to the latest known value so the
// listeners can act on it
exitStatus = exitStatus.and(stepExecution.getExitStatus());
stepExecution.setExitStatus(exitStatus);
exitStatus = exitStatus.and(getCompositeListener().afterStep(stepExecution));
}
catch (Exception e) {
logger.error(String.format("Exception in afterStep callback in step %s in job %s", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e);
}

try {
getJobRepository().updateExecutionContext(stepExecution);
}
catch (Exception e) {
stepExecution.setStatus(BatchStatus.UNKNOWN);
exitStatus = exitStatus.and(ExitStatus.UNKNOWN);
stepExecution.addFailureException(e);
logger.error(String.format("Encountered an error saving batch meta data for step %s in job %s. "
+ "This job is now in an unknown state and should not be restarted.", name, stepExecution.getJobExecution().getJobInstance().getJobName()), e);
}

sample.stop(BatchMetrics.createTimer("step", "Step duration",
Tag.of("job.name", stepExecution.getJobExecution().getJobInstance().getJobName()),
Tag.of("name", stepExecution.getStepName()),
Tag.of("status", stepExecution.getExitStatus().getExitCode())
));
stepExecution.setEndTime(new Date());
stepExecution.setExitStatus(exitStatus);

step 이 실행하고 나서 최종적으로 값을 세팅하는 finally 구문인데 위 구문중

exitStatus = exitStatus.and(getCompositeListener().afterStep(stepExecution));

이 StepExecutionListener 의 afterStep 을 호출하는 구문이고

아래 쪽에 보시면

stepExecution.setEndTime(new Date());

으로 entTime 을 설정하고 있습니다.

그래서 StepExecutionListener 의 afterStep 시점에서는 endTime 이 null 상태가 맞습니다.

스프링 배치 버전 질문

0

139

1

소스코드가 어디에 있나요?

0

122

2

트랜잭션 예외

0

101

1

질문이 있습니다.

0

139

2

ChunkListener 에서 beforeChunk 의 실행 시점 관련 질문

0

145

2

여러 JOB 설정하는법

0

158

2

강의 자료 다른 방법 있을까요?

0

163

1

JobExecution과 JobExecutionContext와의 관계

0

197

2

특정 job만 실행

1

267

1

Batch 성능 질문

0

158

1

ItemReaderAdapter 종료

0

87

1

[ 강좌 Git 브랜치 문의 ] 섹션 9 > JdbcCursorItemReader, JpaCursorItemReader

0

188

2

Spring Batch 배포 질문

0

253

2

spring batch 버전

0

238

2

retry count 관련 질문

0

183

2

StepExecutionListener 의 afterStep 에서 return ExitStatus.FAILED 에 의한 동작에 의문이 갑니다.

0

341

2

jdbc, jpa 커서방식 조회 방식 차이 질문 (강사님께 답변 받고 싶습니다)

0

242

2

Multithread step과 AsyncItemProcessor

0

208

2

job 재실행

0

259

2

bean 생명주기 문제 도와주세요(@Scope("step"), @Autowired)

0

191

1

Multi-threaded-step과 Partitioning 차이 확인

0

183

2

jdbcCursorReader, jdbcPagingReader 질문

0

149

1

step muti-thread 질문

0

114

1

itemSteam open update close 질문

0

117

1