如何在Play Framework 2.4.2 scala中正确安排任务?
发布时间:2020-12-16 09:24:55 所属栏目:安全 来源:网络整理
导读:尝试在Play Framework 2.4.2 Scala中安排这样的任务,但没有运气: import akka.actor.Actorimport play.api.libs.concurrent.Akkaimport scala.concurrent.duration._import play.api.Play.currentimport scala.concurrent.ExecutionContext.Implicits.globa
尝试在Play Framework 2.4.2 Scala中安排这样的任务,但没有运气:
import akka.actor.Actor import play.api.libs.concurrent.Akka import scala.concurrent.duration._ import play.api.Play.current import scala.concurrent.ExecutionContext.Implicits.global class Scheduler extends Actor { override def preStart() { val dbupdate = Akka.system.scheduler.schedule( 0.microseconds,5.minutes,self,"update") val pictureClean = Akka.system.scheduler.schedule( 0.microseconds,30.minutes,"clean") } def receive = { case "update" => updateDB() case "clean" => clean() } def updateDB(): Unit ={ Logger.debug("updates running") } def clean(): Unit ={ Logger.debug("cleanup running") } } 控制台中没有打印任何内容.我做错了什么? 解决方法
好.这里我建立的调度程序的工作代码:
模块: class JobModule extends AbstractModule with AkkaGuiceSupport { def configure() = { bindActor[SchedulerActor]("scheduler-actor") bind(classOf[Scheduler]).asEagerSingleton() } } 调度: class Scheduler @Inject() (val system: ActorSystem,@Named("scheduler-actor") val schedulerActor: ActorRef)(implicit ec: ExecutionContext) { system.scheduler.schedule( 0.microseconds,schedulerActor,"update") system.scheduler.schedule( 30.minutes,30.days,"clean") } 演员: @Singleton class SchedulerActor @Inject() (updater: Updater) extends Actor { def receive = { case "update" => updateDB() case "clean" => clean() } def updateDB(): Unit ={ Logger.debug("updates running") } def clean(): Unit ={ Logger.debug("cleanup running") } } 您还需要在application.conf中添加模块: play.modules.enabled += "modules.JobModule" 希望这会对某人有所帮助 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |