212 lines
6.1 KiB
Java
212 lines
6.1 KiB
Java
package com.interplug.qcast.batch;
|
|
|
|
import java.util.Date;
|
|
import java.util.Map;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.batch.core.Job;
|
|
import org.springframework.batch.core.JobParameters;
|
|
import org.springframework.batch.core.JobParametersBuilder;
|
|
import org.springframework.batch.core.JobParametersInvalidException;
|
|
import org.springframework.batch.core.launch.JobLauncher;
|
|
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
|
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
|
|
import org.springframework.batch.core.repository.JobRestartException;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
public class JobLauncherController {
|
|
private final Map<String, Job> jobs; // 여러 Job을 주입받도록 변경
|
|
|
|
private final JobLauncher jobLauncher;
|
|
|
|
/**
|
|
* 특정 Job을 매핑으로 실행하는 메소드
|
|
*
|
|
* @param jobName
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@GetMapping("/batch/job/{jobName}") // Path Variable로 jobName을 받음
|
|
public String launchJob(@PathVariable String jobName)
|
|
throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException,
|
|
JobParametersInvalidException,
|
|
JobRestartException {
|
|
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder()
|
|
.addString("jobName", jobName)
|
|
.addDate("time", new Date())
|
|
.toJobParameters();
|
|
|
|
jobLauncher.run(job, jobParameters);
|
|
|
|
return "Job " + jobName + " started";
|
|
}
|
|
|
|
/**
|
|
* 스케줄러로 Job을 실행하는 메소드
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 55 23 * * *")
|
|
public String scheduleJobLauncher()
|
|
throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException,
|
|
JobParametersInvalidException,
|
|
JobRestartException {
|
|
|
|
String jobName = "sampleOtherJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder()
|
|
.addString("jobName", jobName)
|
|
.addDate("time", new Date())
|
|
.toJobParameters();
|
|
|
|
jobLauncher.run(job, jobParameters);
|
|
|
|
return "Job " + jobName + " started";
|
|
}
|
|
|
|
/**
|
|
* Q.CAST 판매점 / 사용자 / 즐겨찾기 / 노출 아이템 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
// @Scheduled(cron = "*/5 * * * * *")
|
|
@Scheduled(cron = "0 55 23 * * *")
|
|
public String storeAdditionalInfoJob()
|
|
throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException,
|
|
JobParametersInvalidException,
|
|
JobRestartException {
|
|
|
|
String jobName = "storeAdditionalJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
jobLauncher.run(job, jobParameters);
|
|
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* 아이템 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 0 0 * * *")
|
|
public String materialJob()
|
|
throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException,
|
|
JobParametersInvalidException,
|
|
JobRestartException {
|
|
|
|
String jobName = "materialJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
jobLauncher.run(job, jobParameters);
|
|
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* BOM 아이템 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 0 0 * * *")
|
|
public String bomJob()
|
|
throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException,
|
|
JobParametersInvalidException,
|
|
JobRestartException {
|
|
|
|
String jobName = "bomJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
jobLauncher.run(job, jobParameters);
|
|
|
|
return "OK";
|
|
}
|
|
|
|
/**
|
|
* 영업사원 동기화 배치
|
|
*
|
|
* @return
|
|
* @throws JobInstanceAlreadyCompleteException
|
|
* @throws JobExecutionAlreadyRunningException
|
|
* @throws JobParametersInvalidException
|
|
* @throws JobRestartException
|
|
*/
|
|
@Scheduled(cron = "0 0 0 * * *")
|
|
public String businessChargerJob()
|
|
throws JobInstanceAlreadyCompleteException,
|
|
JobExecutionAlreadyRunningException,
|
|
JobParametersInvalidException,
|
|
JobRestartException {
|
|
|
|
String jobName = "businessChargerJob";
|
|
Job job = jobs.get(jobName);
|
|
if (job == null) {
|
|
return "Job " + jobName + " not found";
|
|
}
|
|
|
|
JobParameters jobParameters =
|
|
new JobParametersBuilder().addDate("time", new Date()).toJobParameters();
|
|
|
|
jobLauncher.run(job, jobParameters);
|
|
|
|
return "OK";
|
|
}
|
|
}
|