Merge pull request #3831 from ractive/master
* pr/3831: Polish contribution Do not attempt to restart non-restartable jobs
This commit is contained in:
commit
5d4bb41e98
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -59,6 +59,7 @@ import org.springframework.util.StringUtils;
|
||||||
* by providing a jobName
|
* by providing a jobName
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Jean-Pierre Bergamin
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class JobLauncherCommandLineRunner implements CommandLineRunner,
|
public class JobLauncherCommandLineRunner implements CommandLineRunner,
|
||||||
|
|
@ -144,7 +145,7 @@ public class JobLauncherCommandLineRunner implements CommandLineRunner,
|
||||||
parameters = incrementer.getNext(new JobParameters());
|
parameters = incrementer.getNext(new JobParameters());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isStoppedOrFailed(previousExecution)) {
|
else if (isStoppedOrFailed(previousExecution) && job.isRestartable()) {
|
||||||
// Retry a failed or stopped execution
|
// Retry a failed or stopped execution
|
||||||
parameters = previousExecution.getJobParameters();
|
parameters = previousExecution.getJobParameters();
|
||||||
// Non-identifying additional parameters can be added to a retry
|
// Non-identifying additional parameters can be added to a retry
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -49,6 +49,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
* Tests for {@link JobLauncherCommandLineRunner}.
|
* Tests for {@link JobLauncherCommandLineRunner}.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Jean-Pierre Bergamin
|
||||||
*/
|
*/
|
||||||
public class JobLauncherCommandLineRunnerTests {
|
public class JobLauncherCommandLineRunnerTests {
|
||||||
|
|
||||||
|
|
@ -124,6 +125,23 @@ public class JobLauncherCommandLineRunnerTests {
|
||||||
assertEquals(1, this.jobExplorer.getJobInstances("job", 0, 100).size());
|
assertEquals(1, this.jobExplorer.getJobInstances("job", 0, 100).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
|
||||||
|
this.job = this.jobs.get("job").preventRestart()
|
||||||
|
.start(this.steps.get("step").tasklet(new Tasklet() {
|
||||||
|
@Override
|
||||||
|
public RepeatStatus execute(StepContribution contribution,
|
||||||
|
ChunkContext chunkContext) throws Exception {
|
||||||
|
throw new RuntimeException("Planned");
|
||||||
|
}
|
||||||
|
}).build()).incrementer(new RunIdIncrementer()).build();
|
||||||
|
this.runner.execute(this.job, new JobParameters());
|
||||||
|
this.runner.execute(this.job, new JobParameters());
|
||||||
|
// A failed job that is not restartable does not re-use the job params of
|
||||||
|
// the last execution, but creates a new job instance when running it again.
|
||||||
|
assertEquals(2, this.jobExplorer.getJobInstances("job", 0, 100).size());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
|
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
|
||||||
this.job = this.jobs.get("job")
|
this.job = this.jobs.get("job")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue