Is anyone aware of a way to create a SupervisorStrategy that executes a Restart of an Actor after a delay? To provide some context I have an actor that queries a DB on startup. If the DB connection is down the Actor will spin until it hits the max retried. It would be nice to delay the restart.
A brute force but unacceptable solution is to do something like the following:
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute)
{
case initEx: ActorInitializationException => {
Thread.sleep(1000)
Restart
}
case t =>
super.supervisorStrategy.decider.applyOrElse(t, (_: Any) => Escalate)
}
However, this seems untenable to me as I want to avoid any blocking code.
Is this just not a concept that should be supported by actors? Should the delay or retry be moved into the Actor implementation itself? This seems counter to the idea of 'let it crash'.
Delay on restart hasn't been implemented yet. Thread.sleep is out of the question performance wise.
I see two choices :