I need to schedule a task for the first day of each month. Up until now, I have been using this:
system.scheduler.schedule(0.microseconds, 30.days, schedulerActor, "update")
But as you may have guessed it, this ends up sometimes running the task twice a month (march) or none a month (february). Is there a better way to schedule the task for the first day of each month using Akka Scheduler?
Built-in Akka scheduler is more a delayer than a scheduler. I would recommend using akka-quartz-scheduler. This module allows you to actually schedule tasks to run when you want.
The usage is simple. Some config:
akka {
quartz {
schedules {
YourScheduleName {
description = "A cron job that fires off every first of the month at 5AM"
expression = "0 0 5 1 1/1 ? *"
}
}
}
}
And then in the code:
case object Tick
val yourActor = system.actorOf(Props[YourActor])
QuartzSchedulerExtension(system).schedule("YourScheduleName", yourActor, Tick)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With