|
|
@ -23,6 +23,7 @@ import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
|
|
import org.springframework.batch.core.BatchStatus;
|
|
|
|
import org.springframework.batch.core.Job;
|
|
|
|
import org.springframework.batch.core.Job;
|
|
|
|
import org.springframework.batch.core.JobExecution;
|
|
|
|
import org.springframework.batch.core.JobExecution;
|
|
|
|
import org.springframework.batch.core.JobExecutionException;
|
|
|
|
import org.springframework.batch.core.JobExecutionException;
|
|
|
@ -31,6 +32,8 @@ import org.springframework.batch.core.configuration.JobRegistry;
|
|
|
|
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
|
|
|
|
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
|
|
|
|
import org.springframework.batch.core.converter.JobParametersConverter;
|
|
|
|
import org.springframework.batch.core.converter.JobParametersConverter;
|
|
|
|
import org.springframework.batch.core.launch.JobLauncher;
|
|
|
|
import org.springframework.batch.core.launch.JobLauncher;
|
|
|
|
|
|
|
|
import org.springframework.batch.core.launch.NoSuchJobException;
|
|
|
|
|
|
|
|
import org.springframework.batch.core.repository.JobRepository;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
|
import org.springframework.context.ApplicationEventPublisher;
|
|
|
|
import org.springframework.context.ApplicationEventPublisher;
|
|
|
@ -60,16 +63,19 @@ public class JobLauncherCommandLineRunner implements CommandLineRunner,
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired(required = false)
|
|
|
|
@Autowired(required = false)
|
|
|
|
private JobRegistry jobRegistry;
|
|
|
|
private JobRegistry jobRegistry;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private JobRepository jobRepository;
|
|
|
|
|
|
|
|
|
|
|
|
private String jobName;
|
|
|
|
private String jobNames;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired(required = false)
|
|
|
|
@Autowired(required = false)
|
|
|
|
private final Collection<Job> jobs = Collections.emptySet();
|
|
|
|
private final Collection<Job> jobs = Collections.emptySet();
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationEventPublisher publisher;
|
|
|
|
private ApplicationEventPublisher publisher;
|
|
|
|
|
|
|
|
|
|
|
|
public void setJobName(String jobName) {
|
|
|
|
public void setJobNames(String jobNames) {
|
|
|
|
this.jobName = jobName;
|
|
|
|
this.jobNames = jobNames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -86,17 +92,28 @@ public class JobLauncherCommandLineRunner implements CommandLineRunner,
|
|
|
|
protected void launchJobFromProperties(Properties properties)
|
|
|
|
protected void launchJobFromProperties(Properties properties)
|
|
|
|
throws JobExecutionException {
|
|
|
|
throws JobExecutionException {
|
|
|
|
JobParameters jobParameters = this.converter.getJobParameters(properties);
|
|
|
|
JobParameters jobParameters = this.converter.getJobParameters(properties);
|
|
|
|
executeRegisteredJobs(jobParameters);
|
|
|
|
|
|
|
|
executeLocalJobs(jobParameters);
|
|
|
|
executeLocalJobs(jobParameters);
|
|
|
|
|
|
|
|
executeRegisteredJobs(jobParameters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void executeRegisteredJobs(JobParameters jobParameters)
|
|
|
|
private void executeRegisteredJobs(JobParameters jobParameters)
|
|
|
|
throws JobExecutionException {
|
|
|
|
throws JobExecutionException {
|
|
|
|
if (this.jobRegistry != null && StringUtils.hasText(this.jobName)) {
|
|
|
|
if (this.jobRegistry != null && StringUtils.hasText(this.jobNames)) {
|
|
|
|
Job job = this.jobRegistry.getJob(this.jobName);
|
|
|
|
String[] jobsToRun = this.jobNames.split(",");
|
|
|
|
JobExecution execution = this.jobLauncher.run(job, jobParameters);
|
|
|
|
for (String jobName : jobsToRun) {
|
|
|
|
if (this.publisher != null) {
|
|
|
|
try {
|
|
|
|
this.publisher.publishEvent(new JobExecutionEvent(execution));
|
|
|
|
Job job = this.jobRegistry.getJob(jobName);
|
|
|
|
|
|
|
|
JobExecution previousExecution = jobRepository.getLastJobExecution(jobName, jobParameters);
|
|
|
|
|
|
|
|
if (previousExecution == null || previousExecution.getStatus() != BatchStatus.COMPLETED) {
|
|
|
|
|
|
|
|
JobExecution execution = this.jobLauncher.run(job, jobParameters);
|
|
|
|
|
|
|
|
if (this.publisher != null) {
|
|
|
|
|
|
|
|
this.publisher.publishEvent(new JobExecutionEvent(execution));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NoSuchJobException nsje) {
|
|
|
|
|
|
|
|
logger.debug("No job found in registry for job name: " + jobName);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -104,8 +121,9 @@ public class JobLauncherCommandLineRunner implements CommandLineRunner,
|
|
|
|
private void executeLocalJobs(JobParameters jobParameters)
|
|
|
|
private void executeLocalJobs(JobParameters jobParameters)
|
|
|
|
throws JobExecutionException {
|
|
|
|
throws JobExecutionException {
|
|
|
|
for (Job job : this.jobs) {
|
|
|
|
for (Job job : this.jobs) {
|
|
|
|
if (StringUtils.hasText(this.jobName)) {
|
|
|
|
if (StringUtils.hasText(this.jobNames)) {
|
|
|
|
if (!PatternMatchUtils.simpleMatch(this.jobName, job.getName())) {
|
|
|
|
String[] jobsToRun = this.jobNames.split(",");
|
|
|
|
|
|
|
|
if (!PatternMatchUtils.simpleMatch(jobsToRun, job.getName())) {
|
|
|
|
logger.debug("Skipped job: " + job.getName());
|
|
|
|
logger.debug("Skipped job: " + job.getName());
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|