-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Closed as not planned
Closed as not planned
Copy link
Labels
status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by anothertype: bugA general bugA general bug
Description
When using JobLauncherApplicationRunner
, if we pass an arbitrary JobName
, the spring application terminates with a success exit code without failure.
If the job name is entered incorrectly by mistake, it could be mistaken for success even though no job was actually executed.
It would be good to add validation whether the job name is defined in application.
sol. 1
public class JobLauncherApplicationRunner implements ApplicationRunner, Ordered, ApplicationEventPublisherAware {
...
@Value("${spring.batch.job.fail-on-unknown-name:false}")
private boolean failOnUnknownName;
@PostConstruct
public void validate() {
if (this.jobs.size() > 1 && !StringUtils.hasText(this.jobName)) {
throw new IllegalArgumentException("Job name must be specified in case of multiple jobs");
}
if (failOnUnknownName == true && this.jobs.stream().noneMatch(job -> StringUtils.equals(this.jobName, job.getName()))) {
throw IllegalArgumentException("No such job name : [$jobName]")
}
}
sol. 2
public class JobExecutionExitCodeGenerator implements ApplicationListener<JobExecutionEvent>, ExitCodeGenerator {
@Override
public int getExitCode() {
if (this.executions.isEmpty()) {
return 127;
}
for (JobExecution execution : this.executions) {
if (execution.getStatus().ordinal() > 0) {
return execution.getStatus().ordinal();
}
}
return 0;
}
Metadata
Metadata
Assignees
Labels
status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by anothertype: bugA general bugA general bug