Compare commits

..

No commits in common. "9a37eb79b425627610a41541066fca8298a2c13c" and "a84632244927e26f90321d2bba2192c13c773cef" have entirely different histories.

View File

@ -32,6 +32,8 @@ public class JobLauncherController {
@Value("${spring.profiles.scheduler}") @Value("${spring.profiles.scheduler}")
private String scheduler; private String scheduler;
// 현재 실행 중인 Job 추적을 위한 Set
private final Set<String> runningJobs = ConcurrentHashMap.newKeySet();
/** /**
* 특정 Job을 매핑으로 실행하는 메소드 * 특정 Job을 매핑으로 실행하는 메소드
* *
@ -57,35 +59,31 @@ public class JobLauncherController {
return resultMap; return resultMap;
} }
// 실행 중인 Job 확인 (데이터베이스 기반) // 실행 중인 Job 확인
if (isJobRunning(jobName)) { if (runningJobs.contains(jobName) || isJobRunning(jobName)) {
log.warn("Job {} is already running, skipping execution", jobName); log.warn("Job {} is already running, skipping execution", jobName);
resultMap.put("code", "FAILED"); resultMap.put("code", "FAILED");
resultMap.put("message", "Job "+ jobName +" is already running, skipping execution"); resultMap.put("message", "Job "+ jobName +" is already running, skipping execution");
return resultMap; return resultMap;
} }
try {
log.info("Starting job: {}", jobName);
JobParameters jobParameters = new JobParametersBuilder().addString("jobName", jobName) JobParameters jobParameters = new JobParametersBuilder().addString("jobName", jobName)
.addDate("time", new Date()).toJobParameters(); .addDate("time", new Date()).toJobParameters();
JobExecution jobExecution = jobLauncher.run(job, jobParameters); JobExecution jobExecution = jobLauncher.run(job, jobParameters);
BatchStatus status = jobExecution.getStatus(); BatchStatus status = jobExecution.getStatus();
ExitStatus exitStatus = jobExecution.getExitStatus(); ExitStatus exitStatus = jobExecution.getExitStatus();
resultMap.put("code", status.toString()); resultMap.put("code", status.toString());
resultMap.put("message", exitStatus.getExitDescription()); resultMap.put("message", exitStatus.getExitDescription());
// return "Job " + jobName + " started"; // return "Job " + jobName + " started";
return resultMap; return resultMap;
} catch (Exception e) {
resultMap.put("code", "FAILED");
resultMap.put("message", e.getMessage());
return resultMap;
}
} }
/** /**
@ -225,8 +223,8 @@ public class JobLauncherController {
return "Scheduler disabled"; return "Scheduler disabled";
} }
// 실행 중인 Job 확인 (데이터베이스 기반) // 실행 중인 Job 확인
if (isJobRunning(jobName)) { if (runningJobs.contains(jobName) || isJobRunning(jobName)) {
log.warn("Job {} is already running, skipping execution", jobName); log.warn("Job {} is already running, skipping execution", jobName);
return "Job already running"; return "Job already running";
} }