Updated scenario-task
This commit is contained in:
@@ -30,6 +30,8 @@ docker run spring/scenario-task:latest
|
||||
|
||||
### Properties
|
||||
|
||||
All properties should be prefixed with `io.spring.`
|
||||
|
||||
* *jobName* - The name associated with the batch job. The default is "scenario-job".
|
||||
* *stepName* - The name associated with the single step for the job. The default is "scenario-step".
|
||||
* *failBatch* - If true, the batch will throw a {@link ExpectedException}. Defaults to false.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.3</version>
|
||||
<version>2.7.18</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>io.spring</groupId>
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
<properties>
|
||||
<java.version>8</java.version>
|
||||
<spring-cloud.version>2021.0.0</spring-cloud.version>
|
||||
<test-container-version>1.15.3</test-container-version>
|
||||
<spring-cloud.version>2021.0.5</spring-cloud.version>
|
||||
<test-container-version>1.19.7</test-container-version>
|
||||
<oracle-jdbc.version>21.1.0.0</oracle-jdbc.version>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@ package io.spring.scenariotask;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.task.configuration.EnableTask;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableTask
|
||||
public class ScenarioTaskApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -117,4 +117,17 @@ public class ScenarioProperties {
|
||||
public void setIncludeRunidIncrementer(boolean includeRunidIncrementer) {
|
||||
this.includeRunidIncrementer = includeRunidIncrementer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScenarioProperties{" +
|
||||
"jobName='" + jobName + '\'' +
|
||||
", stepName='" + stepName + '\'' +
|
||||
", failBatch=" + failBatch +
|
||||
", failTask=" + failTask +
|
||||
", launchBatchJob=" + launchBatchJob +
|
||||
", pauseInSeconds=" + pauseInSeconds +
|
||||
", includeRunidIncrementer=" + includeRunidIncrementer +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.task.configuration.EnableTask;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
@@ -52,7 +51,6 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@EnableTask
|
||||
@EnableBatchProcessing
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(ScenarioProperties.class)
|
||||
@@ -61,10 +59,7 @@ public class ScenarioTaskConfiguration {
|
||||
private static final Log logger = LogFactory.getLog(ScenarioTaskConfiguration.class);
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(
|
||||
value = "io.spring.launchBatchJob",
|
||||
havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnProperty(value = "io.spring.launch-batch-job", havingValue = "true", matchIfMissing = true)
|
||||
static class BatchConfig {
|
||||
@Autowired
|
||||
public JobBuilderFactory jobBuilderFactory;
|
||||
@@ -80,16 +75,17 @@ public class ScenarioTaskConfiguration {
|
||||
|
||||
@Bean
|
||||
public Job pausedemoAgain() {
|
||||
logger.info("properties=:" + properties);
|
||||
SimpleJobBuilder jobBuilder = this.jobBuilderFactory.get(properties.getJobName())
|
||||
.start(this.stepBuilderFactory.get(properties.getStepName())
|
||||
.allowStartIfComplete(true)
|
||||
.tasklet((contribution, chunkContext) -> {
|
||||
logger.info(String.format("%s is starting", properties.getStepName()));
|
||||
if (properties.getPauseInSeconds() > 0) {
|
||||
logger.info(String.format("%s is pausing", properties.getStepName()));
|
||||
logger.info(String.format("%s is pausing for %d seconds", properties.getStepName(), properties.getPauseInSeconds()));
|
||||
Thread.sleep(properties.getPauseInSeconds() * 1000);
|
||||
}
|
||||
logger.info(String.format("%s is completing", properties.getStepName()));
|
||||
|
||||
if (jobExecutionCount() == 1 && properties.isFailBatch()) {
|
||||
throw new ExpectedException("Exception thrown during Batch Execution");
|
||||
}
|
||||
@@ -151,6 +147,10 @@ public class ScenarioTaskConfiguration {
|
||||
public ApplicationRunner applicationRunner(ScenarioProperties properties) {
|
||||
return args -> {
|
||||
logger.info("ApplicationRunner Executing for ScenarioTaskApplication");
|
||||
if (!properties.isLaunchBatchJob() && properties.getPauseInSeconds() > 0) {
|
||||
logger.info(String.format("Task is pausing for %d seconds", properties.getPauseInSeconds()));
|
||||
Thread.sleep(properties.getPauseInSeconds() * 1000);
|
||||
}
|
||||
if (properties.isFailTask()) {
|
||||
throw new ExpectedException("Exception thrown during Task Execution");
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ScenarioTaskApplicationTests {
|
||||
}
|
||||
|
||||
private static TaskExplorer taskExplorer() {
|
||||
TaskExecutionDaoFactoryBean taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean(dataSource, "TASK_");
|
||||
TaskExecutionDaoFactoryBean taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean(dataSource);
|
||||
return new SimpleTaskExplorer(taskExecutionDaoFactoryBean);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user