I am using shedlock to implement a use-case of distributed locking. My app is running on 20 machines, and I want scheduler to be executed once in every 5 minutes in any 1 machine by using implicit distributed locking provided by shedlock library.
Scheduler:
@Scheduled(cron = "0 */5 * * * *")
@SchedulerLock(name = "executeTaskLock",
lockAtLeastFor = "1m",
lockAtMostFor = "4m")
public void executeTask() throws Exception {
LockAssert.assertLocked();
// task executes here which completed in around (400ms - 2s)
}
Config:
@Bean
public JedisPool jedisPoolForSchedulerLocking() {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(2);
jedisPoolConfig.setMaxIdle(2);
jedisPoolConfig.setMinIdle(1);
jedisPoolConfig.setMaxWaitMillis(500);
return new JedisPool(jedisPoolConfig, {host}, {port}, {timeout}, {port});
}
@Bean
public LockProvider lockProvider(@Qualifier("jedisPoolForSchedulerLocking") JedisPool jedisPool) {
return new JedisLockProvider(jedisPool, "PRD");
}
Issue:
I am seeing sometimes scheduler is missing the runs, for instance it runs at 12:25, 12:30 and then runs at 12:45, missed 2 runs here. Actual task completes in around (400ms - 3s), thus I have setup 1m
and 4m
as lockAtLeastFor
and lockAtMostFor
. config seems correct to me.
Doesn't know what's failing here exactly. As per official docs this can run more than once(which is fine for my use-case) but should never miss the runs.
pom.xml :
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
<version>4.42.0</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-redis-jedis</artifactId>
<version>4.42.0</version>
</dependency>
<java.version>1.8</java.version>
<spring-boot.version>2.2.1.RELEASE</spring-boot.version>