Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to schedule a global period Akka job across multiple processes?

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)
  }
}
like image 811
ripper234 Avatar asked Mar 31 '13 08:03

ripper234


1 Answers

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.

like image 107
sourcedelica Avatar answered Nov 03 '22 01:11

sourcedelica