Skip to content

Instantly share code, notes, and snippets.

@natansil
Last active April 17, 2021 16:52
Show Gist options
  • Save natansil/1c6b100de3f5e323062a914809e0cf19 to your computer and use it in GitHub Desktop.
Save natansil/1c6b100de3f5e323062a914809e0cf19 to your computer and use it in GitHub Desktop.
package com.wix.cronulla.example;
import com.wix.cronulla.example.GetTasks;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.leader.LeaderSelectorListenerAdapter;
import java.util.concurrent.ExecutorService;
public class LeaderNodeCronScheduler extends LeaderSelectorListenerAdapter {
public LeaderNodeCronScheduler(GetTasks getTasks, ExecutorService executorService) { }
@Override
public void takeLeadership(CuratorFramework curatorFramework) throws Exception {
try {
while (true) {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
// process currently available scheduled tasks (getTasks) to run on a separate thread pool (executorService)
// delay next iteration
}
} catch (InterruptedException ex) {
} finally {
// Stop processing scheduling tasks
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment