Akka Stream - Timer or Scheduler like CRON

ⅰ亾dé卋堺 提交于 2019-12-05 01:18:24

问题


I use Akka Stream on Scala. I'd like to set a scheduler which runs on every 24:00. I tried to search for it. But I could't find what I want to do. Could you tell me how to write code?


回答1:


Use the build in Akka scheduler, see: http://doc.akka.io/docs/akka/current/scala/scheduler.html

You can use the scheduler like:

system.scheduler.schedule(
  initialDelay = FiniteDuration(/*offset to next 24:00*/),
  interval = FiniteDuration(24, TimeUnit.HOURS),
  receiver = self,
  message = ScheduleAkkaStream
)

Then in the actor, when the ScheduleAkkaStream is received, run the job




回答2:


The most commonly used one is akka quartz scheduler: https://github.com/enragedginger/akka-quartz-scheduler

This one written by me and has no additional dependencies, a bit more lightweight than using quartz with fewer bells and whistles: https://github.com/johanandren/akron




回答3:


This is mentioned in a comment but should really by the preferred solution using only akka-streams:

Source.tick(0.seconds, 24.hours, Done).runForeach { x =>
   //do something   
}


来源:https://stackoverflow.com/questions/38475895/akka-stream-timer-or-scheduler-like-cron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!