Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
add shedlock for revocation list sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ubhaller committed Jul 21, 2021
1 parent 3189c8b commit 310786b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
package ch.admin.bag.covidcertificate.backend.verifier.ws.config;

import ch.admin.bag.covidcertificate.backend.verifier.ws.client.RevocationListSyncer;
import net.javacrumbs.shedlock.core.LockAssert;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
Expand All @@ -19,6 +22,7 @@

@Configuration
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "PT10M")
public class SchedulingConfig {

private static final Logger logger = LoggerFactory.getLogger(SchedulingConfig.class);
Expand All @@ -31,7 +35,9 @@ public SchedulingConfig(RevocationListSyncer revocationListSyncer) {

// Sync revocation list every full hour (default)
@Scheduled(cron = "${revocationList.sync.cron:0 0 * ? * *}")
@SchedulerLock(name = "revocation_list_sync", lockAtLeastFor = "PT15S")
public void syncRevocationList() {
LockAssert.assertLocked();
revocationListSyncer.updateRevokedCerts();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import org.flywaydb.core.Flyway;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand Down Expand Up @@ -192,4 +195,15 @@ public ValueSetsController valueSetsController() throws IOException, NoSuchAlgor
public RestTemplate restTemplate() {
return RestTemplateHelper.getRestTemplate();
}

@Bean
public LockProvider lockProvider(DataSource dataSource) {
return new JdbcTemplateLockProvider(
JdbcTemplateLockProvider.Configuration.builder()
.withTableName("t_shedlock")
.withJdbcTemplate(new JdbcTemplate(dataSource))
// Works on Postgres, MySQL, MariaDb, MS SQL, Oracle, DB2, HSQL and H2
.usingDbTime()
.build());
}
}

0 comments on commit 310786b

Please sign in to comment.