use of org.springframework.batch.core.JobParametersIncrementer in project spring-boot by spring-projects.
the class JobLauncherCommandLineRunner method getNextJobParameters.
private JobParameters getNextJobParameters(Job job, JobParameters additionalParameters) {
String name = job.getName();
JobParameters parameters = new JobParameters();
List<JobInstance> lastInstances = this.jobExplorer.getJobInstances(name, 0, 1);
JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
Map<String, JobParameter> additionals = additionalParameters.getParameters();
if (lastInstances.isEmpty()) {
// Start from a completely clean sheet
if (incrementer != null) {
parameters = incrementer.getNext(new JobParameters());
}
} else {
List<JobExecution> previousExecutions = this.jobExplorer.getJobExecutions(lastInstances.get(0));
JobExecution previousExecution = previousExecutions.get(0);
if (previousExecution == null) {
// Normally this will not happen - an instance exists with no executions
if (incrementer != null) {
parameters = incrementer.getNext(new JobParameters());
}
} else if (isStoppedOrFailed(previousExecution) && job.isRestartable()) {
// Retry a failed or stopped execution
parameters = previousExecution.getJobParameters();
// Non-identifying additional parameters can be removed to a retry
removeNonIdentifying(additionals);
} else if (incrementer != null) {
// New instance so increment the parameters if we can
parameters = incrementer.getNext(previousExecution.getJobParameters());
}
}
return merge(parameters, additionals);
}
Aggregations