parent
5f9f29c43a
commit
e90a59ec29
@ -1,28 +1,50 @@
|
|||||||
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 Job runSyncJob; // ✅ Spring Batch의 Job 타입
|
private final JobExplorer jobExplorer; // 실행 중 Job 확인용
|
||||||
|
private final Job runSyncJob;
|
||||||
|
|
||||||
@Scheduled(fixedRate = 60000) // 1분마다 실행
|
/**
|
||||||
public void runJob() throws Exception {
|
* Kubeflow run 동기화 배치 Job
|
||||||
JobParameters params = new JobParametersBuilder()
|
* - 1분마다 실행 시도
|
||||||
.addLong("timestamp", System.currentTimeMillis()) // 중복 실행 방지
|
* - 실행 중인 Job이 있으면 스킵
|
||||||
.toJobParameters();
|
*/
|
||||||
|
@Scheduled(fixedDelay = 60000) // 이전 실행이 끝난 후 1분 뒤 다시 실행
|
||||||
|
public void runJob() {
|
||||||
|
try {
|
||||||
|
boolean running = !jobExplorer.findRunningJobExecutions("runSyncJob").isEmpty();
|
||||||
|
|
||||||
jobLauncher.run(runSyncJob, params);
|
if (running) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in new issue