ShedLock est-il asocial ?
Faisons un ADR
Instructions à déclenchement programmé
Performances critiques
Option 1 : cron
machine hôte à configurer
script shell à maintenir
accès concurrent à la DB
Option 2 : k8s cronJob
cluster k8s à configurer
config k8s à maintenir
accès concurrent à la DB
Option 3 : Spring @Scheduled
même langage
co-localisé avec le code applicatif
interface d'accès partagée

GO PROD !
Loïc Broquet
lolo101



Problème

Problème
Application multi-instances


Solution
Synchro sur une ressource partagée

- BDD (SQL / NoSQL)
- MessageQueue
- Cache
- FileSystem
- S3
Solution
ShedLock
https://github.com/lukas-krecan/ShedLock
ShedLock
How to use
@Scheduled(cron = "0 */15 * * * *")
@SchedulerLock(name = "scheduledTaskName", lockAtMostFor = "14m", lockAtLeastFor = "14m")
public void scheduledTask() {
// do something
}
@Bean
public LockProvider lockProvider(DataSource dataSource) {
return new JdbcTemplateLockProvider(
JdbcTemplateLockProvider.Configuration.builder()
.withJdbcTemplate(new JdbcTemplate(dataSource))
.usingDbTime()
.build()
);
}

Problème

Problème

Setup de test ?
Tests d'intégration

Avec TestContainers
Tests d'intégration

user
company
permission
ff4j
databasechangelog
shedlock
1ère Idée : nettoyer la table shedlock
item #13 in https://debug.guide
2è idée : lire le code
item #15 in https://debug.guide

2è idée : lire le code
item #15 in https://debug.guide

@Autowired
JdbcTemplateLockProvider lockProvider;
@BeforeEach
void before() {
lockProvider.clearCache();
}
Fix
Pour aller plus loin : RTFM
item #15 in https://debug.guide

https://debug.guide
ShedLock est-il asocial ?
By Loïc Broquet
ShedLock est-il asocial ?
- 15