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