Skip to content

WeirdBob/alphadog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alphadog

Only run if you're the alpha

This project uses Zookeeper to ensure that only one process can run a task at a given time. It uses a Curator InterProcessSemaphoreMutex to ensure unicity.

running is as simple as this :

try (AlphaDog alphaDog = new AlphaDog("zoo.keep.er:2181")) {
  // this will run only if alpha
  alphaDog.runIfAlpha(() -> {System.err.println("Alpha wanabee");}, "lockName");
	}

The last time a particular lock was acquired is saved, so you can optionnally provide a Duration to ensure a task will not run too often.

try (AlphaDog alphaDog = new AlphaDog("zoo.keep.er:2181")) {
  // this will run only if alpha and if last run was at least 1 hour ago
  alphaDog.runIfAlpha(() -> {System.err.println("Alpha wanabee");}, "lockName", Duration.of(1L, ChronoUnit.HOURS));
	}

About

Only run if you're the alpha

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages