Search code examples
scalaakka-stream

Akka Stream - Timer or Scheduler like CRON


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?


Solution

  • 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