So let's say I have an akka cluster of 5 nodes. 4 are "worker nodes" and 1 is the "master" node, the master implemented via an akka singleton (
http://doc.akka.io/docs/akka/snapshot/contrib/cluster-singleton.html ).
This all works good. If the master node dies, a new master is elected. Cool!
Now what I need to fit on top of this, is scheduled tasks. I want the master to schedule a unit of work every 30 seconds, and give it to one of his workers. How do I do this?
On a single machine you just do a scheduled task.. but if I do that on all nodes of the cluster, I would get the task happening 5 times. Possible ideas:
a) Schedule task on every machine. If your machine does not have the master node running on it, skip it. So it only runs once. (would need to see if I can figure out which node a singleton proxy points to, for the implementation of this)
b) Schedule task on every machine. When the schedule hits, send a message to master to say HEY DO THE TASK NOW... master would need to keep track of when he last did it, and if he already did it in the last 30 seconds skip it (so say he gets 5 messages to do work for task A, he would do the first task and delete the next 4).
c) ?????
Part of the trick is as nodes crash and the master singleton moves around, the tasks need to keep happening. I am ok with a task being skipped once in a while (like during a master switch), but would want to generally prevent them from being run multiple times.