first Commit!!!
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.spring.infra.quartz;
|
||||
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.configuration.JobLocator;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
public class QuartzJobLauncher extends QuartzJobBean {
|
||||
|
||||
private String jobName;
|
||||
private JobLauncher jobLauncher;
|
||||
private JobLocator jobLocator;
|
||||
|
||||
public void setJobName(String jobName) {
|
||||
this.jobName = jobName;
|
||||
}
|
||||
|
||||
public void setJobLauncher(JobLauncher jobLauncher) {
|
||||
this.jobLauncher = jobLauncher;
|
||||
}
|
||||
|
||||
public void setJobLocator(JobLocator jobLocator) {
|
||||
this.jobLocator = jobLocator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeInternal(@NonNull JobExecutionContext context) throws JobExecutionException {
|
||||
try {
|
||||
Job job = jobLocator.getJob(jobName);
|
||||
JobParameters params = new JobParametersBuilder()
|
||||
.addString("JobID", String.valueOf(System.currentTimeMillis()))
|
||||
.toJobParameters();
|
||||
jobLauncher.run(job, params);
|
||||
} catch (Exception e) {
|
||||
throw new JobExecutionException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user