1

I'm trying to use BackoffSupervisor to delay the restart. I've given 10.sec as minimum backoff but on Exception it is restarting the actor immediately.

Here is code:

  `object Task2Implementation extends App {
    val system = ActorSystem("system")
    val actor = system.actorOf(BackoffSupervisor.props(BackoffOpts.onStop(
      Props[TestActor],
      "testActor",
      10.seconds,
      30.seconds,
      0.2
    ).withSupervisorStrategy(OneForOneStrategy(){
      case ex:Exception =>
        log.error("Going To Stop!")
        Stop
    })))

    actor ! BadStuff
  }`

Code of TestActor class:

  `class TestActor extends Actor {
    override def postStop(): Unit = log.info("Actor {} is stopped!", self.path)

    override def preRestart(reason: Throwable, message: Option[Any]): Unit = {
      log.info("In preRestart: reason -> {}, message -> {}", reason.getMessage, message.getOrElse(""))
    }

    def receive = {
      case BadStuff => throw new Exception("Bad Stuff!")

      case _ => log.info("Child Received Message!")
    }
  }`
Zaryab Ali
  • 19
  • 3

0 Answers0