I have two actors:
ProcessManager which handles some processes in the system (for example, user registration, purchase, etc)
Notifier - should notify the user if some error occurred in ProcessManager. I need to catch failure of ProcessManager actor (it was failed and stopped for what ever reason, for example, because of ActorInitializationException or max restart time reached and Process manager actor was stopped).
class ProcessManager extends Actor {
override def receive: Receive = {
...
}
}
class Notifier extends Actor {
override def receive: Receive = {
PROCESS MANAGER ACTOR FAILED AND STOPPED =>
// Here I need to catch failure of ProcessManager actor
// (it was failed and stopped for what ever
// reason, for example, because of ActorInitializationException
// or max restart time reached and Process manager actor was stopped).
//
// Then do some stuff, for example, send message to the client via web socket.
}
}
class MyController @Inject() (cc: ControllerComponents, actorSystem: ActorSystem)
(implicit exec: ExecutionContext) extends AbstractController(cc) {
// I need to catch failure of processManager in this actor.
val notifier = actorSystem.actorOf(Props(classOf[Notifier]))
def registerUser = Action.async {
// Actor may be stopped because of ActorInitializationException here
val processManager = actorSystem.actorOf(Props(classOf[ProcessManager]))
...
// OR it may be stopped here for any reason.
processManager ! "some message which will fail and stop pm actor"
Future.successfull(Ok("Thanks."))
}
}
How can I catch termination (because of failure) of ProcessManager actor inside Notifier actor?
EDIT Let me explain the context of my problem.
I'm creating PM actor in Play controller and send the message to it (Tell) and I return Ok response immediately to the user. PM actor creates another child actor and during creation, ActorInitializationException is thrown. I need to notify the user (via web socket, using Notifier actor), that something went wrong.