From 501d75681b80affe15e59903bc7a9e0649994626 Mon Sep 17 00:00:00 2001 From: Glenn Renfro Date: Tue, 15 Nov 2022 20:10:15 -0500 Subject: [PATCH] Deprecating the CommandLineRunnerOrder renaming it to ApplicaitonRunnerOrder This is to reflect the foundation class of CommandLineRunner which is ApplicationRunner --- docs/src/main/asciidoc/batch.adoc | 6 +++--- .../configuration/TaskBatchProperties.java | 20 ++++++++++++++----- ...bLauncherApplicationRunnerFactoryBean.java | 2 +- ...TaskJobLauncherAutoConfigurationTests.java | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/docs/src/main/asciidoc/batch.adoc b/docs/src/main/asciidoc/batch.adoc index 65f458f0..958854b1 100644 --- a/docs/src/main/asciidoc/batch.adoc +++ b/docs/src/main/asciidoc/batch.adoc @@ -209,10 +209,10 @@ 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`]) -This functionality uses a new `CommandLineRunner` that replaces the one provided by Spring +This functionality uses a new `ApplicationRunner` that replaces the one provided by Spring Boot. By default, it is configured with the same order. However, if you want to customize -the order in which the `CommandLineRunner` is run, you can set its order by setting the -`spring.cloud.task.batch.commandLineRunnerOrder` property. To have your task return the +the order in which the `ApplicationRunner` is run, you can set its order by setting the +`spring.cloud.task.batch.applicationRunnerOrder` property. To have your task return the exit code based on the result of the batch job execution, you need to write your own `CommandLineRunner`. //TODO Great place for a example showing how a custom CommandLineRunner diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchProperties.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchProperties.java index 562e7ef4..fe49a83c 100644 --- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchProperties.java +++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchProperties.java @@ -38,12 +38,12 @@ public class TaskBatchProperties { private String jobNames = ""; /** - * The order for the {@code CommandLineRunner} used to run batch jobs when + * The order for the {@code ApplicationRunner} used to run batch jobs when * {@code spring.cloud.task.batch.fail-on-job-failure=true}. Defaults to 0 (same as * the - * {@link org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner}). + * {@link org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner}). */ - private int commandLineRunnerOrder = 0; + private int applicationRunnerOrder = 0; /** * Fixed delay in milliseconds that Spring Cloud Task will wait when checking if @@ -60,12 +60,22 @@ public class TaskBatchProperties { this.jobNames = jobNames; } + @Deprecated public int getCommandLineRunnerOrder() { - return this.commandLineRunnerOrder; + return this.applicationRunnerOrder; } + @Deprecated public void setCommandLineRunnerOrder(int commandLineRunnerOrder) { - this.commandLineRunnerOrder = commandLineRunnerOrder; + this.applicationRunnerOrder = commandLineRunnerOrder; + } + + public int getApplicationRunnerOrder() { + return this.applicationRunnerOrder; + } + + public void setApplicationRunnerOrder(int applicationRunnerOrder) { + this.applicationRunnerOrder = applicationRunnerOrder; } public long getFailOnJobFailurePollInterval() { diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherApplicationRunnerFactoryBean.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherApplicationRunnerFactoryBean.java index e80ee874..50861c83 100644 --- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherApplicationRunnerFactoryBean.java +++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherApplicationRunnerFactoryBean.java @@ -72,7 +72,7 @@ public class TaskJobLauncherApplicationRunnerFactoryBean implements FactoryBean< else { this.jobName = taskBatchProperties.getJobNames(); } - this.order = taskBatchProperties.getCommandLineRunnerOrder(); + this.order = taskBatchProperties.getApplicationRunnerOrder(); this.jobRepository = jobRepository; } diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java index 5d8acbd4..91d97d62 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java @@ -53,7 +53,7 @@ public class TaskJobLauncherAutoConfigurationTests { @Test public void testAutoBuiltDataSourceWithTaskJobLauncherCLROrder() { this.contextRunner.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true", - "spring.cloud.task.batch.commandLineRunnerOrder=100").run(context -> { + "spring.cloud.task.batch.applicationRunnerOrder=100").run(context -> { assertThat(context.getBean(TaskJobLauncherApplicationRunner.class).getOrder()).isEqualTo(100); }); }