scala – 如何使用Play Framework 2.1安排小时工作?
发布时间:2020-12-16 09:13:30 所属栏目:安全 来源:网络整理
导读:在播放1它只是: @Every(value = "1h")public class WebsiteStatusReporter extends Job { @Override public void doJob() throws Exception { // do something }} 什么是相当于Play 2.1? 我知道Play使用akka和i found this code sample: import play.api.
在播放1它只是:
@Every(value = "1h") public class WebsiteStatusReporter extends Job { @Override public void doJob() throws Exception { // do something } } 什么是相当于Play 2.1? 我知道Play使用akka和i found this code sample: import play.api.libs.concurrent.Execution.Implicits._ Akka.system.scheduler.schedule(0.seconds,30.minutes,testActor,"tick") 但是作为Scala noob我不明白如何工作.有人可以提供一个完整的工作实例(端到端)? 解决方法
这是
code of mine的摘录:
import scala.concurrent.duration.DurationInt import akka.actor.Props.apply import play.api.Application import play.api.GlobalSettings import play.api.Logger import play.api.Play import play.api.libs.concurrent.Execution.Implicits.defaultContext import play.api.libs.concurrent.Akka import akka.actor.Props import actor.ReminderActor object Global extends GlobalSettings { override def onStart(app: Application) { val controllerPath = controllers.routes.Ping.ping.url play.api.Play.mode(app) match { case play.api.Mode.Test => // do not schedule anything for Test case _ => reminderDaemon(app) } } def reminderDaemon(app: Application) = { Logger.info("Scheduling the reminder daemon") val reminderActor = Akka.system(app).actorOf(Props(new ReminderActor())) Akka.system(app).scheduler.schedule(0 seconds,5 minutes,reminderActor,"reminderDaemon") } } 它只是在应用程序开始时启动一个守护进程,然后每5分钟启动一个守护进程.它使用Play 2.1,它的工作原理. 请注意,此代码使用Global object,允许在应用程序启动时运行一些代码. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |