Updated to add metadata for Conditionals
Also renamed camel-cased properties to cononical format. resolves #442
This commit is contained in:
committed by
Janne Valkealahti
parent
c719f8b1f9
commit
d2c90c5256
@@ -38,7 +38,7 @@ public class TaskBatchProperties {
|
||||
|
||||
/**
|
||||
* The order for the {@coce CommandLineRunner} used to run batch jobs when
|
||||
* {@code spring.cloud.task.batch.failOnJobFailure=true}. Defaults to 0 (same as the
|
||||
* {@code spring.cloud.task.batch.fail-on-job-failure=true}. Defaults to 0 (same as the
|
||||
* {@link org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner}).
|
||||
*/
|
||||
private int commandLineRunnerOrder = 0;
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(name = "spring.cloud.task.batch.failOnJobFailure", havingValue = "true", matchIfMissing = false)
|
||||
@ConditionalOnProperty(name = "spring.cloud.task.batch.fail-on-job-failure", havingValue = "true", matchIfMissing = false)
|
||||
@EnableConfigurationProperties(TaskBatchProperties.class)
|
||||
public class TaskJobLauncherAutoConfiguration {
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"defaultValue": "true",
|
||||
"name": "spring.cloud.task.batch.listener.enabled",
|
||||
"description": "This property is used to determine if a task will be linked to the batch jobs that are run.",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"defaultValue": "false",
|
||||
"name": "spring.cloud.task.batch.fail-on-job-failure",
|
||||
"description": "This property is used to determine if a task app should return with a non zero exit code if a batch job fails.",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"defaultValue": "true",
|
||||
"name": "spring.cloud.task.batch.events.enabled",
|
||||
"description": "This property is used to determine if a task should listen for batch events.",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"defaultValue": "true",
|
||||
"name": "spring.cloud.task.batch.events.chunk.enabled",
|
||||
"description": "This property is used to determine if a task should listen for batch chunk events.",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"defaultValue": "true",
|
||||
"name": "spring.cloud.task.batch.events.item-process.enabled",
|
||||
"description": "This property is used to determine if a task should listen for batch item processed events.",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"defaultValue": "true",
|
||||
"name": "spring.cloud.task.batch.events.item-read.enabled",
|
||||
"description": "This property is used to determine if a task should listen for batch item read events.",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"defaultValue": "true",
|
||||
"name": "spring.cloud.task.batch.events.item-write.enabled",
|
||||
"description": "This property is used to determine if a task should listen for batch item write events.",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"defaultValue": "true",
|
||||
"name": "spring.cloud.task.batch.events.job-execution.enabled",
|
||||
"description": "This property is used to determine if a task should listen for batch job execution events.",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"defaultValue": "true",
|
||||
"name": "spring.cloud.task.batch.events.skip.enabled",
|
||||
"description": "This property is used to determine if a task should listen for batch skip events.",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"defaultValue": "true",
|
||||
"name": "spring.cloud.task.batch.events.step-execution.enabled",
|
||||
"description": "This property is used to determine if a task should listen for batch step execution events.",
|
||||
"type": "java.lang.Boolean"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class TaskJobLauncherAutoConfigurationTests {
|
||||
@Test
|
||||
public void testAutoBuiltDataSourceWithTaskJobLauncherCLR() {
|
||||
this.contextRunner.
|
||||
withPropertyValues("spring.cloud.task.batch.failOnJobFailure=true").
|
||||
withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true").
|
||||
run(context -> {
|
||||
assertThat(context).hasSingleBean(TaskJobLauncherCommandLineRunner.class);
|
||||
assertThat(context).doesNotHaveBean(JobLauncherCommandLineRunner.class);
|
||||
@@ -56,7 +56,7 @@ public class TaskJobLauncherAutoConfigurationTests {
|
||||
@Test
|
||||
public void testAutoBuiltDataSourceWithTaskJobLauncherCLROrder() {
|
||||
this.contextRunner.
|
||||
withPropertyValues("spring.cloud.task.batch.failOnJobFailure=true",
|
||||
withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"spring.cloud.task.batch.commandLineRunnerOrder=100").
|
||||
run(context -> {
|
||||
assertThat(context.getBean(TaskJobLauncherCommandLineRunner.class)
|
||||
|
||||
@@ -65,7 +65,7 @@ public class TaskJobLauncherCommandLineRunnerTests {
|
||||
|
||||
@Test
|
||||
public void testTaskJobLauncherCLRSuccessFail() {
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true" };
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.fail-on-job-failure=true" };
|
||||
boolean isExceptionThrown = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication
|
||||
@@ -85,7 +85,7 @@ public class TaskJobLauncherCommandLineRunnerTests {
|
||||
@Test
|
||||
public void testTaskJobLauncherPickOneJob() {
|
||||
String[] enabledArgs = new String[] {
|
||||
"--spring.cloud.task.batch.failOnJobFailure=true",
|
||||
"--spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"--spring.cloud.task.batch.jobNames=jobSucceed" };
|
||||
boolean isExceptionThrown = false;
|
||||
try {
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.integration.support.leader.LockRegistryLeaderInitiato
|
||||
import org.springframework.integration.support.locks.LockRegistry;
|
||||
|
||||
/**
|
||||
* When spring.cloud.task.singleInstanceEnabled is set to true this listener will create a lock for the task
|
||||
* When spring.cloud.task.single-instance-enabled is set to true this listener will create a lock for the task
|
||||
* based on the spring.cloud.task.name. If a lock already exists this Listener will throw
|
||||
* a TaskExecutionException. If this listener is added manually, then it should
|
||||
* be added as the first listener in the chain.
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.util.CollectionUtils;
|
||||
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task", name = "singleInstanceEnabled", havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task", name = "single-instance-enabled", havingValue = "true")
|
||||
public class SingleTaskConfiguration {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -74,7 +74,7 @@ public class TaskProperties {
|
||||
/**
|
||||
* Declares the maximum amount of time (in millis) that a task execution can
|
||||
* hold a lock to prevent another task from executing with a specific task
|
||||
* name when the singleInstanceEnabled is set to true. Default time is: Integer.MAX_VALUE.
|
||||
* name when the single-instance-enabled is set to true. Default time is: Integer.MAX_VALUE.
|
||||
*/
|
||||
private int singleInstanceLockTtl = Integer.MAX_VALUE;
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"defaultValue": "false",
|
||||
"name": "spring.cloud.task.single-instance-enabled",
|
||||
"description": "This property is used to determine if a task will execute if another task with the same app name is running.",
|
||||
"type": "java.lang.Boolean"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -42,7 +42,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = {TaskProperties.class, SimpleTaskConfiguration.class, SingleTaskConfiguration.class})
|
||||
@TestPropertySource(properties = {
|
||||
"spring.cloud.task.singleInstanceEnabled=true",
|
||||
"spring.cloud.task.single-instance-enabled=true",
|
||||
})
|
||||
public class SimpleSingleTaskAutoConfigurationTests {
|
||||
@Autowired
|
||||
|
||||
@@ -44,7 +44,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class})
|
||||
@TestPropertySource(properties = {
|
||||
"spring.cloud.task.singleInstanceEnabled=true",
|
||||
"spring.cloud.task.single-instance-enabled=true",
|
||||
})
|
||||
public class SimpleSingleTaskAutoConfigurationWithDataSourceTests {
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ returned from the task is the same as a boot application.
|
||||
To override this behavior and allow the task to return an exit code other than zero when a
|
||||
batch job returns an
|
||||
https://docs.spring.io/spring-batch/4.0.x/reference/html/step.html#conditionalFlow[ExitStatus]
|
||||
of `FAILED`, set `spring.cloud.task.batch.failOnJobFailure` to `true`. Then the exit code
|
||||
of `FAILED`, set `spring.cloud.task.batch.fail-on-job-failure` to `true`. Then the exit code
|
||||
can be 1 (the default) or be based on the
|
||||
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-spring-application.html#boot-features-application-exit[specified
|
||||
`ExitCodeGenerator`])
|
||||
|
||||
@@ -346,14 +346,14 @@ the exit messages from both the `onTaskStartup` and `onTaskFailed`.
|
||||
|
||||
Spring Cloud Task lets you establish that only one task with a given task name can be run
|
||||
at a time. To do so, you need to establish the <<features-task-name, task name>> and set
|
||||
`spring.cloud.task.singleInstanceEnabled=true` for each task execution. While the first
|
||||
`spring.cloud.task.single-instance-enabled=true` for each task execution. While the first
|
||||
task execution is running, any other time you try to run a task with the same
|
||||
<<features-task-name, task name>> and`spring.cloud.task.singleInstanceEnabled=true`, the
|
||||
<<features-task-name, task name>> and`spring.cloud.task.single-instance-enabled=true`, the
|
||||
task fails with the following error message: `Task with name "application" is already
|
||||
running.` The default value for `spring.cloud.task.singleInstanceEnabled` is `false`. The
|
||||
following example shows how to set `spring.cloud.task.singleInstanceEnabled` to `true`:
|
||||
running.` The default value for `spring.cloud.task.single-instance-enabled` is `false`. The
|
||||
following example shows how to set `spring.cloud.task.single-instance-enabled` to `true`:
|
||||
|
||||
`spring.cloud.task.singleInstanceEnabled=true or false`
|
||||
`spring.cloud.task.single-instance-enabled=true or false`
|
||||
|
||||
To use this feature, you must add the following Spring Integration dependencies to your
|
||||
application:
|
||||
|
||||
@@ -192,7 +192,7 @@ public class TaskStartTests {
|
||||
|
||||
@Test
|
||||
public void testDuplicateTaskExecutionWithSingleInstanceEnabled() throws Exception {
|
||||
String params[] = {"--spring.cloud.task.singleInstanceEnabled=true",
|
||||
String params[] = {"--spring.cloud.task.single-instance-enabled=true",
|
||||
"--spring.cloud.task.name=foo"};
|
||||
boolean testFailed = false;
|
||||
try {
|
||||
@@ -210,7 +210,7 @@ public class TaskStartTests {
|
||||
testFailed = true;
|
||||
}
|
||||
assertTrue("Expected TaskExecutionException for because of " +
|
||||
"singleInstanceEnabled is enabled", testFailed);
|
||||
"single-instance-enabled is enabled", testFailed);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"defaultValue": "true",
|
||||
"name": "spring.cloud.task.events.enabled",
|
||||
"description": "This property is used to determine if a task app should emit task events.",
|
||||
"type": "java.lang.Boolean"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user