Updated timestamp-batch and timestamp-task to Boot 3.
This commit is contained in:
7
.github/actions/build-sample-app/action.yml
vendored
7
.github/actions/build-sample-app/action.yml
vendored
@@ -38,6 +38,10 @@ inputs:
|
||||
docker-images-override:
|
||||
description: 'csv of docker image tags to use when pushing (parallel array to docker-images)'
|
||||
required: false
|
||||
java-version:
|
||||
description: 'Java Version. Default is 8'
|
||||
required: false
|
||||
default: '8'
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
@@ -49,8 +53,7 @@ runs:
|
||||
|
||||
- uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: adopt
|
||||
java-version: 8
|
||||
java-version: ${{ inputs.java-version }}
|
||||
cache: maven
|
||||
|
||||
- name: Maven build
|
||||
|
||||
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@@ -321,8 +321,8 @@ jobs:
|
||||
docker-push: ${{ inputs.maven-build-only != true }}
|
||||
docker-username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
docker-password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
docker-images: >-
|
||||
springcloudtask/timestamp-task:2.0.2
|
||||
java-version: '17'
|
||||
docker-images: 'springcloudtask/timestamp-task:3.0.0'
|
||||
|
||||
timestamp-batch:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -337,5 +337,5 @@ jobs:
|
||||
docker-push: ${{ inputs.maven-build-only != true }}
|
||||
docker-username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
docker-password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
docker-images: >-
|
||||
springcloudtask/timestamp-batch-task:2.0.2
|
||||
java-version: '17'
|
||||
docker-images: 'springcloudtask/timestamp-batch-task:3.0.0'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
if [ "$TIMESTAMP_BATCH_TASK_VERSION" = "" ]; then
|
||||
TIMESTAMP_BATCH_TASK_VERSION=2.0.2
|
||||
TIMESTAMP_BATCH_TASK_VERSION=3.0.0
|
||||
fi
|
||||
./mvnw -o clean install -DskipTests
|
||||
./mvnw -o spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=springcloud/timestamp-batch-task:$TIMESTAMP_BATCH_TASK_VERSION
|
||||
|
||||
@@ -5,18 +5,18 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.5</version>
|
||||
<version>3.0.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>io.spring</groupId>
|
||||
<artifactId>timestamp-batch-task</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<name>timestamp-task</name>
|
||||
<version>3.0.0</version>
|
||||
<name>timestamp-batch-task</name>
|
||||
<description>Simple Timestamp sample.</description>
|
||||
|
||||
<properties>
|
||||
<java.version>8</java.version>
|
||||
<spring-cloud.version>2021.0.5</spring-cloud.version>
|
||||
<spring-cloud.version>2022.0.2</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -16,17 +16,43 @@
|
||||
|
||||
package io.spring;
|
||||
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.task.configuration.EnableTask;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@EnableTask
|
||||
@SpringBootApplication
|
||||
@EnableBatchProcessing
|
||||
public class BatchJobApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BatchJobApplication.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BatchJobApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TimestampTask timestampTask(JobLauncher jobLauncher, Job job1, Job job2) {
|
||||
return new TimestampTask(jobLauncher, job1, job2);
|
||||
}
|
||||
|
||||
public static class TimestampTask implements CommandLineRunner {
|
||||
private final JobLauncher launcher;
|
||||
private final Job job1;
|
||||
private final Job job2;
|
||||
|
||||
public TimestampTask(JobLauncher launcher, Job job1, Job job2) {
|
||||
this.launcher = launcher;
|
||||
this.job1 = job1;
|
||||
this.job2 = job2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
launcher.run(job1, new JobParameters());
|
||||
launcher.run(job2, new JobParameters());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,103 +16,83 @@
|
||||
|
||||
package io.spring.configuration;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.configuration.annotation.BatchConfigurer;
|
||||
import org.springframework.batch.core.configuration.annotation.DefaultBatchConfigurer;
|
||||
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
|
||||
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({ TimestampBatchTaskProperties.class })
|
||||
public class TimestampBatchTaskConfiguration {
|
||||
public class TimestampBatchTaskConfiguration extends DefaultBatchConfiguration {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TimestampBatchTaskProperties.class);
|
||||
|
||||
@Autowired
|
||||
public JobBuilderFactory jobBuilderFactory;
|
||||
|
||||
@Autowired
|
||||
public StepBuilderFactory stepBuilderFactory;
|
||||
|
||||
@Autowired
|
||||
private TimestampBatchTaskProperties config;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "spring.datasource.driver-class-name", matchIfMissing = true)
|
||||
public DataSource dataSource() {
|
||||
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
||||
.addScript("/org/springframework/batch/core/schema-h2.sql")
|
||||
.generateUniqueName(true).build();
|
||||
}
|
||||
/**
|
||||
* Override default transaction isolation level 'ISOLATION_REPEATABLE_READ' which Oracle does not
|
||||
* support.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value = "spring.datasource.driver", havingValue = "oracle.jdbc.OracleDriver")
|
||||
static class OracleBatchConfig {
|
||||
@Bean
|
||||
BatchConfigurer oracleBatchConfigurer(DataSource dataSource) {
|
||||
return new DefaultBatchConfigurer() {
|
||||
@Override
|
||||
public JobRepository getJobRepository() {
|
||||
JobRepositoryFactoryBean factoryBean = new JobRepositoryFactoryBean();
|
||||
factoryBean.setDatabaseType("ORACLE");
|
||||
factoryBean.setDataSource(dataSource);
|
||||
factoryBean.setTransactionManager(getTransactionManager());
|
||||
factoryBean.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED");
|
||||
try {
|
||||
return factoryBean.getObject();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new BeanCreationException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public DataSourceTransactionManager getTransactionManager() {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Bean
|
||||
public Step job1step1(JobRepository jobRepository, PlatformTransactionManager springCloudTaskTransactionManager) {
|
||||
return new StepBuilder("job1step1", jobRepository)
|
||||
.tasklet(getTasklet("Job1 was run with date %s"), springCloudTaskTransactionManager).build();
|
||||
}
|
||||
|
||||
private Tasklet getTasklet(String format) {
|
||||
return (contribution, chunkContext) -> {
|
||||
DateFormat dateFormat = new SimpleDateFormat(config.getFormat());
|
||||
logger.info(String.format(format, dateFormat.format(new Date())));
|
||||
return RepeatStatus.FINISHED;
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job1() {
|
||||
return jobBuilderFactory.get("job1")
|
||||
.start(stepBuilderFactory.get("job1step1")
|
||||
.tasklet((contribution, chunkContext) -> {
|
||||
DateFormat dateFormat = new SimpleDateFormat(config.getFormat());
|
||||
logger.info(String.format("Job1 was run with date %s", dateFormat.format(new Date())));
|
||||
return RepeatStatus.FINISHED;
|
||||
})
|
||||
.build())
|
||||
public Job job1(JobRepository jobRepository, Step job1step1) {
|
||||
return new JobBuilder("job1", jobRepository)
|
||||
.start(job1step1)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job2() {
|
||||
return jobBuilderFactory.get("job2")
|
||||
.start(stepBuilderFactory.get("job2step1")
|
||||
.tasklet((contribution, chunkContext) -> {
|
||||
DateFormat dateFormat = new SimpleDateFormat(config.getFormat());
|
||||
logger.info(String.format("Job2 was run with date %s", dateFormat.format(new Date())));
|
||||
return RepeatStatus.FINISHED;
|
||||
})
|
||||
.build())
|
||||
public Step job2step1(JobRepository jobRepository,
|
||||
PlatformTransactionManager springCloudTaskTransactionManager
|
||||
) {
|
||||
return new StepBuilder("job2step1", jobRepository)
|
||||
.tasklet(getTasklet("Job2 was run with date %s"), springCloudTaskTransactionManager)
|
||||
.build();
|
||||
}
|
||||
@Bean
|
||||
public Job job2(JobRepository jobRepository, Step job2step1) {
|
||||
return new JobBuilder("job2", jobRepository)
|
||||
.start(job2step1)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
logging.level.org.springframework.cloud.task=debug
|
||||
logging.level.org.springframework.cloud.task=debug
|
||||
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
|
||||
@@ -32,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
@SpringBootTest
|
||||
public class TimestampBatchTaskTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -5,18 +5,18 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.5</version>
|
||||
<version>3.0.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>io.spring</groupId>
|
||||
<artifactId>timestamp-task</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<version>3.0.0</version>
|
||||
<name>timestamp-task</name>
|
||||
<description>Simple Timestamp sample.</description>
|
||||
|
||||
<properties>
|
||||
<java.version>8</java.version>
|
||||
<spring-cloud.version>2021.0.5</spring-cloud.version>
|
||||
<spring-cloud.version>2022.0.2</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
Reference in New Issue
Block a user