• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

step endtime 질문

22.01.13 15:32 작성 조회수 276

0

안녕하세요. 

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

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

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

답변 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 상태가 맞습니다.