We run this code:
scheduler.schedule(1 minute, 1 minute) { triggerOperations.tick() }
when starting our application, where scheduler is an Akka actorSystem.scheduler. If tick() throws an exception, then it is never called again!
I checked the documentation, but cannot find any statement that this is expected. Mostly the description is "Schedules a function to be run repeatedly with an initial delay and a frequency", with no mention that if the function throws an excpetion the task will stop firing.
Our akka version is 2.3.2.
http://doc.akka.io/docs/akka/2.3.4/scala/scheduler.html http://doc.akka.io/api/akka/2.0/akka/actor/Scheduler.html
Is this behavior expected? Is it documented anywhere?
When in doubt, go to source. The code is a bit terse, but this fragment:
override def run(): Unit = {
try {
runnable.run()
val driftNanos = clock() - getAndAdd(delay.toNanos)
if (self.get != null)
swap(schedule(executor, this, Duration.fromNanos(Math.max(delay.toNanos - driftNanos, 1))))
} catch {
case _: SchedulerException ⇒ // ignore failure to enqueue or terminated target actor
}
}
shows that if your runnable throws, scheduler does not reschedule the next execution (which happens inside swap as far as I understand).
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