Created
April 2, 2012 07:10
-
-
Save shinobu-aoki/2281360 to your computer and use it in GitHub Desktop.
GlobalSettingsとAkkaを使ってplay 2.0でJob(Actor)を定期実行する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api._ | |
import play.api.libs.concurrent.Akka | |
import akka.actor._ | |
import akka.util.duration._ | |
object Global extends GlobalSettings { | |
case class LogMessage() | |
class DateActor extends Actor { | |
def receive = { | |
case LogMessage => Logger.info(new java.util.Date().toString) | |
} | |
} | |
var actorJob: Cancellable = _ | |
override def onStart(app: Application) { | |
Logger.info("Application has started") | |
val actorSystem = Akka.system(app) | |
val dateActor = actorSystem.actorOf(Props[DateActor], name = "dateactor") | |
actorJob = actorSystem.scheduler.schedule(0 seconds, 1 minutes, dateActor, LogMessage) | |
} | |
override def onStop(app: Application) { | |
actorJob.cancel() | |
Logger.info("Application shutdown...") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment