Reputation: 659
I am working with a persistent actor in Scala using EventStore as a backend. Testing is specs2-based. During initialization of the spec class, inside the constructor of the other class that is being instantiated, I ask my actor for something and, if EventStore is not running, get
Could not create an instance of
com.optrak.opkakka.authentication.AuthenticationManagementSpec
caused by
akka.pattern.AskTimeoutException: Ask timed out on
[Actor[akka://com-optrak-opkakka-authentication-AuthenticationManagementSpec/user/$b/AuthenticationModel#1565142060]] after [2000 ms]
Where AuthenticationModel
is my actor's name.
The questions are,
first, why doesn't my actor respond to ask? The asked command is not persisted and the actor hasn't received any persisted commands to change its state at this point, because it has just been created.
second, how can I detect that the backend is not running beforehand to issue a warning to the user?
Upvotes: 0
Views: 149
Reputation: 659
Using pointers from ktoso (thanks!) and a small test project, I found my own way. I handle RecoveryFailure
in my persistent actor as suggested by some error messages by throwing onward a new IllegalStateException
with a suggestion to check if EventStore is running. Then the supervisor gets a shot at handling this using its custom strategy:
override def supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 3){
case _: IllegalStateException => Restart
case t =>
super.supervisorStrategy.decider.applyOrElse(t, (_: Any) => Escalate)
}
After my persistent actor is restarted three times, everything terminates (by the way, what REALLY happens under the hood here?) and I have all the stack traces and error messages in the log file.
Upvotes: 1
Reputation: 13130
1) It most likely issued a recovery request (as each PersistentActor
does upon starting) and since the Journal is not started (or is it?) it is awaiting for the response (recovery) before it will take on any external messages. You can disable recovery on startup by override def preStart() = ()
as document in Persistence docs.
2) In a "plain old all synchronously writing to a database" how do you know a database is down? If a write fails. Similarly in Akka Persistence if you persist()
and it fails you'll get back a PersistenceFailure
as explained in the docs.
Upvotes: 0