Search code examples
scalaakkaakka-supervision

Akka Actor Restart After a Time lapse


I have a Supervisor actor that creates a couple of child actors. I have also defined a Supervision strategy that does a OneToOne handling:

  override val supervisorStrategy =
    OneForOneStrategy() {
      case _ =>
        logger.info("doing restart")
        Restart
    }

I would like to know how could I introduce a Timeout to this Restart so that I want for let's say 5 seconds before I restart the children? I do not see any Akka documentation pointing me to any configurable timeouts. Any clues? I do not want to have Thread.sleep(...). It is definitely out of the equation. Any other suggestions?


Solution

  • How about overriding the OneForOneStrategy with the parameters as:

    OneForOneStrategy(maxNrOfRetries = 6, withinTimeRange = 1.minute) {
      ...
      ...
    }
    

    This would ensure that the child actors are restarted only 6 times within a span of 1 minute!