I'm using Akka in Play Framework instead of a Job, to schedule code to run every X seconds. I have a sort of cluster (running on Heroku, currently on 1 dyno but there might be a few concurrent instances occasionally).
Is there an easy way to make the "job" run every N seconds globally in the entire cluster? I know that Quartz supports out-of-process storage/sync mechanisms e.g. a DB - can I use something similar in Scala?
This is the actor setup that is run on Play start:
object Global extends GlobalSettings {
override def onStart(app: Application) {
val monitorActor = Akka.system.actorOf(Props[MonitorLoadJob], name = "monitorLoad")
Akka.system.scheduler.schedule(0 seconds, 10 seconds, monitorActor, Tick)
}
}
Check out ClusterSingletonManager
.
For some use cases it is convenient and sometimes also mandatory to ensure that you have exactly one actor of a certain type running somewhere in the cluster.
Some examples:
- single point of responsibility for certain cluster-wide consistent decisions, or coordination of actions across the cluster system
It requires running Akka Cluster but it's made for this type of scenario.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With