Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Critical Actor trait and use in ZPM #2312

Merged
merged 2 commits into from
Jan 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ZonalParkingManager(
maxSearchRadius: Double,
boundingBox: Envelope,
mnlMultiplierParameters: ParkingMNL.ParkingMNLConfig
) extends Actor
) extends beam.utils.CriticalActor
with ActorLogging {

if (maxSearchRadius < minSearchRadius) {
Expand Down
21 changes: 21 additions & 0 deletions src/main/scala/beam/utils/CriticalActor.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package beam.utils

import akka.actor.{Actor, ActorLogging}
import akka.actor.Actor.Receive

trait CriticalActor extends Actor with ActorLogging {
val isCriticalExceptionHandler: PartialFunction[Throwable, Boolean] = { case _: Throwable => true }

override def aroundReceive(r: Receive, msg: Any): Unit = {
try {
super.aroundReceive(r, msg)
} catch {
case ex: Throwable =>
if (isCriticalExceptionHandler(ex)) {
log.error(ex, "Critical actor encountered an unrecoverable exception, so killing the entire application.")
Thread.sleep(1000) //This makes sure the log is written before crashing out
sys.exit(123)
}
}
}
}