Quartz Job/Trigger listeners on clustered environment, Listening every node how?

55 Views Asked by At

I have built a project using Quartz with a clustered environment. And when an unelected node reaches CronTrigger, I want to make a certain logic run. However, JobListener/TriggerListener in Quartz only listens on the elected node. Is there a way to get logic running on all nodes?

1

There are 1 best solutions below

0
ozkanpakdil On

It is not possible with quartz described here. But you can use spring @Scheduled

In any config bean define the annotation like below @EnableScheduling

@Configuration
@EnableScheduling
public class SpringConfig {
    ...
}

And choose any function to run in cron, and define like below

@Scheduled(cron = "0 15 10 15 * ?")
public void scheduleTaskUsingCronExpression() { 
    long now = System.currentTimeMillis() / 1000;
    System.out.println(
      "schedule tasks using cron jobs - " + now);
}

or for fixed delay

@Scheduled(fixedDelay = 1000)
public void scheduleFixedDelayTask() {
    System.out.println(
      "Fixed delay task - " + System.currentTimeMillis() / 1000);
}

Reference: https://spring.io/guides/gs/scheduling-tasks/