This commit is contained in:
mindol1004
2024-08-29 17:15:37 +09:00
parent ecbf7f8698
commit 58495710ec
16 changed files with 272 additions and 29 deletions

View File

@@ -12,6 +12,7 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* Quartz 작업을 실행하는 Spring Batch Job 실행기 클래스입니다.
@@ -31,13 +32,16 @@ import lombok.RequiredArgsConstructor;
* @see JobLauncher
* @see JobRegistry
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class QuartzJobLauncher extends QuartzJobBean {
private static final String JOB_PARAMETERS_INSTANCE_KEY = "InstanceId";
private static final String JOB_PARAMETERS_TIMESTAMP_KEY = "timestamp";
private final JobLauncher jobLauncher;
private final JobRegistry jobRegistry;
private String jobName;
public void setJobName(String jobName) {
@@ -61,11 +65,13 @@ public class QuartzJobLauncher extends QuartzJobBean {
try {
Job job = jobRegistry.getJob(jobName);
JobParameters params = new JobParametersBuilder()
.addString("JobID", String.valueOf(System.currentTimeMillis()))
.addString(JOB_PARAMETERS_INSTANCE_KEY, context.getScheduler().getSchedulerInstanceId())
.addLong(JOB_PARAMETERS_TIMESTAMP_KEY, System.currentTimeMillis())
.toJobParameters();
jobLauncher.run(job, params);
} catch (Exception e) {
throw new JobExecutionException(e);
log.error("job execution exception! - {}", e.getCause());
throw new JobExecutionException();
}
}