[REMOVE] JobExplorer 기반 실행 중 체크 로직 제거 및 runIdCache null 체크 추가

main
bjkim 8 months ago
parent e90a59ec29
commit 69d29885ed

@ -1,50 +1,28 @@
package kr.re.etri.autoflow.batch; package kr.re.etri.autoflow.batch;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job; import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
@Slf4j
@Configuration @Configuration
@EnableScheduling @EnableScheduling
@RequiredArgsConstructor @RequiredArgsConstructor
public class BatchScheduler { public class BatchScheduler {
private final JobLauncher jobLauncher; private final JobLauncher jobLauncher;
private final JobExplorer jobExplorer; // 실행 중 Job 확인용 private final Job runSyncJob; // ✅ Spring Batch의 Job 타입
private final Job runSyncJob;
/** @Scheduled(fixedDelay = 60000) // 1분마다 실행
* Kubeflow run Job public void runJob() throws Exception {
* - 1 JobParameters params = new JobParametersBuilder()
* - Job .addLong("timestamp", System.currentTimeMillis()) // 중복 실행 방지
*/ .toJobParameters();
@Scheduled(fixedDelay = 60000) // 이전 실행이 끝난 후 1분 뒤 다시 실행
public void runJob() {
try {
boolean running = !jobExplorer.findRunningJobExecutions("runSyncJob").isEmpty();
if (running) { jobLauncher.run(runSyncJob, params);
log.info("runSyncJob is already running. Skipping this schedule.");
return;
}
JobParameters params = new JobParametersBuilder()
.addLong("timestamp", System.currentTimeMillis())
.toJobParameters();
log.info("Launching runSyncJob...");
jobLauncher.run(runSyncJob, params);
} catch (Exception e) {
log.error("Error launching runSyncJob", e);
}
} }
} }

@ -120,6 +120,7 @@ public class KubeflowRunBatchConfig {
} }
// 캐시 또는 DB 중복 검사 // 캐시 또는 DB 중복 검사
assert runIdCache != null;
if (runIdCache.get(runId) != null || kubeflowRunRepository.existsByRunId(runId)) { if (runIdCache.get(runId) != null || kubeflowRunRepository.existsByRunId(runId)) {
runIdCache.put(runId, true); runIdCache.put(runId, true);
return null; return null;

Loading…
Cancel
Save