0

I am trying to use Shedlock for running scheduled task in a clustered environment. But the moment I add @EnableSchedulerLock annotation, the scheduler task does not start at all.

I see that I need to provide LockProvider. I am using Redis/Lettuce in a clustered environment and I don't see a integration with lettuce shedlock.

Is there a way I can still use Shedlock ?

My maven dependency is :

 <dependency>
     <groupId>net.javacrumbs.shedlock</groupId>
     <artifactId>shedlock-spring</artifactId>
     <version>4.24.0</version>
 </dependency>
   

Main Spring application is

@SpringBootApplication
@EnableSchedulerLock(defaultLockAtMostFor = "10s")
public class MainApplication {
....

ScheduledTask class

@Component
@EnableScheduling
public class SchedulerTask {
    @Scheduled(fixedRate = 3000)
    @SchedulerLock(name = "scheduledTaskPods", lockAtMostFor = "5s", lockAtLeastFor = "2s")
    public void populateDatacenterPods()  {
        LockAssert.assertLocked();
        System.out.println("This is a schedule test");

    }
}
user1805280
  • 251
  • 1
  • 5
  • 14
  • You also need `@EnablScheduling` and that should be on the application class as well not the component. – M. Deinum Aug 11 '21 at 06:42
  • @M.Deinum I can certainly do that . Current challenge is how do I use Redis/Lettuce as a LockProvider ? Any pointers ? – user1805280 Aug 11 '21 at 16:18
  • 1
    Okay Figured. We need to pass LettuceConnectionFactory in this format @Bean public LockProvider lockProvider() { return new RedisLockProvider(lettuceConnectionFactory(), "default"); } Here, lettuceConnectionFactory() is returning "LettuceConnectionFactory – user1805280 Aug 11 '21 at 17:06

0 Answers0