Compare commits

..

No commits in common. "3e91ebe0b7ed33cf7937c0703dfaea304d919cf8" and "6452e1996e5eb89cf9e820e33082d107bd77e7d5" 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();
ExitStatus exitStatus = jobExecution.getExitStatus();
resultMap.put("code", status.toString());
resultMap.put("message", exitStatus.getExitDescription());
// return "Job " + jobName + " started"; BatchStatus status = jobExecution.getStatus();
return resultMap; ExitStatus exitStatus = jobExecution.getExitStatus();
} catch (Exception e) {
resultMap.put("code", "FAILED"); resultMap.put("code", status.toString());
resultMap.put("message", e.getMessage()); resultMap.put("message", exitStatus.getExitDescription());
return resultMap;
}
// return "Job " + jobName + " started";
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";
} }