From 7c1cf052f8f0cf24505814c6206975f7320288ae Mon Sep 17 00:00:00 2001 From: Felix Dittrich <31076102+f11h@users.noreply.github.com> Date: Wed, 9 Feb 2022 18:07:38 +0100 Subject: [PATCH] Fix: Missing Shedlock Config (#120) * Add Shedlock Config * Update pom.xml --- pom.xml | 2 +- .../testresult/TestResultApplication.java | 2 + .../testresult/config/ShedLockConfig.java | 54 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/java/app/coronawarn/testresult/config/ShedLockConfig.java diff --git a/pom.xml b/pom.xml index 78b86db..627e6b0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ app.coronawarn.testresult cwa-testresult-server - 1.4.2-SNAPSHOT + 1.4.3-SNAPSHOT jar cwa-testresult-server diff --git a/src/main/java/app/coronawarn/testresult/TestResultApplication.java b/src/main/java/app/coronawarn/testresult/TestResultApplication.java index eebd63f..56ed53d 100644 --- a/src/main/java/app/coronawarn/testresult/TestResultApplication.java +++ b/src/main/java/app/coronawarn/testresult/TestResultApplication.java @@ -22,6 +22,7 @@ package app.coronawarn.testresult; import lombok.extern.slf4j.Slf4j; +import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @@ -30,6 +31,7 @@ @Slf4j @EnableScheduling +@EnableSchedulerLock(defaultLockAtMostFor = "PT30S") @EnableJpaAuditing @EnableWebSecurity @SpringBootApplication diff --git a/src/main/java/app/coronawarn/testresult/config/ShedLockConfig.java b/src/main/java/app/coronawarn/testresult/config/ShedLockConfig.java new file mode 100644 index 0000000..ff7c987 --- /dev/null +++ b/src/main/java/app/coronawarn/testresult/config/ShedLockConfig.java @@ -0,0 +1,54 @@ +/* + * Corona-Warn-App / cwa-testresult-server + * + * (C) 2020, T-Systems International GmbH + * + * Deutsche Telekom AG and all other contributors / + * copyright owners license this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this + * file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package app.coronawarn.testresult.config; + +import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder; + +import javax.sql.DataSource; +import lombok.RequiredArgsConstructor; +import net.javacrumbs.shedlock.core.LockProvider; +import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.core.JdbcTemplate; + +@Configuration +@RequiredArgsConstructor +public class ShedLockConfig { + + private final DataSource dataSource; + + /** + * Creates a LockProvider for ShedLock. + * + * @return LockProvider + */ + @Bean + public LockProvider lockProvider() { + return new JdbcTemplateLockProvider(builder() + .withTableName("shedlock") + .withJdbcTemplate(new JdbcTemplate(dataSource)) + .usingDbTime() + .build() + ); + } +}