[Scheduler] Implemented scheduler using config only
This commit is contained in:
parent
83eef96c0f
commit
043debba33
|
|
@ -48,6 +48,9 @@ public class ScheduleJobConfig {
|
||||||
|
|
||||||
@Column(name = "sjc_job_code", nullable = false, length = 50)
|
@Column(name = "sjc_job_code", nullable = false, length = 50)
|
||||||
private String sjcJobCode;
|
private String sjcJobCode;
|
||||||
|
|
||||||
|
@Column(name = "sjc_next_job_code", nullable = false, length = 50)
|
||||||
|
private String sjcNextJobCode;
|
||||||
|
|
||||||
@Column(name = "sjc_job_name", nullable = false, length = 100)
|
@Column(name = "sjc_job_name", nullable = false, length = 100)
|
||||||
private String sjcJobName;
|
private String sjcJobName;
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,9 @@ public class SchedulerCoreService {
|
||||||
body.getSuccessCount(),
|
body.getSuccessCount(),
|
||||||
body.getFailCount()
|
body.getFailCount()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 연관된 다음 작업 바로 수행
|
||||||
|
triggerNextJobIfExists(job, LocalDateTime.now());
|
||||||
} else {
|
} else {
|
||||||
logService.markFailed(
|
logService.markFailed(
|
||||||
log.getSjlId(),
|
log.getSjlId(),
|
||||||
|
|
@ -211,6 +214,58 @@ public class SchedulerCoreService {
|
||||||
|
|
||||||
return snapshot;
|
return snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void triggerNextJobIfExists(ScheduleJobConfig job, LocalDateTime now) {
|
||||||
|
|
||||||
|
if (job.getSjcNextJobCode() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScheduleJobConfig nextJob =
|
||||||
|
configRepository.findBySjcJobCode(job.getSjcNextJobCode())
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (nextJob == null || !Boolean.TRUE.equals(nextJob.getSjcEnabled())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info(
|
||||||
|
"Trigger chained job. from={} to={}",
|
||||||
|
job.getSjcJobCode(),
|
||||||
|
nextJob.getSjcJobCode()
|
||||||
|
);
|
||||||
|
|
||||||
|
// cron 판단 없이 바로 실행
|
||||||
|
evaluateAndRunChained(nextJob, now);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void evaluateAndRunChained(
|
||||||
|
ScheduleJobConfig job,
|
||||||
|
LocalDateTime now
|
||||||
|
) {
|
||||||
|
// 중복 실행 방지
|
||||||
|
if (logService.isRunning(job.getSjcId())) {
|
||||||
|
log.info("Chained job already running. jobCode={}", job.getSjcJobCode());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDateTime from = now
|
||||||
|
.minusHours(job.getSjcLookbackHours() != null ? job.getSjcLookbackHours() : 0)
|
||||||
|
.minusMinutes(job.getSjcOverlapMinutes() != null ? job.getSjcOverlapMinutes() : 0);
|
||||||
|
|
||||||
|
ScheduleJobLog runningLog = logService.createRunningLog(
|
||||||
|
job.getSjcId(),
|
||||||
|
now,
|
||||||
|
job.getSjcLookbackHours(),
|
||||||
|
job.getSjcOverlapMinutes(),
|
||||||
|
job.getSjcMaxRecords(),
|
||||||
|
"scheduler-chain"
|
||||||
|
);
|
||||||
|
|
||||||
|
executeWorker(job, from, now, runningLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue