Skip to content

Instantly share code, notes, and snippets.

@jchapuis
Created May 10, 2020 20:18
Show Gist options
  • Save jchapuis/0c7a940582842b85e926283a86721663 to your computer and use it in GitHub Desktop.
Save jchapuis/0c7a940582842b85e926283a86721663 to your computer and use it in GitHub Desktop.
Markdium-Orchestrating startup and shutdown in Scala
class ClusterUpAndServiceBoundCheck(system: ActorSystem) extends (() => Future[Boolean]) {
private val cluster = Cluster(system)
discard {
CoordinatedShutdown(system).serviceUnbind(
() =>
Future.successful {
serviceUnbound.set(true)
Done
},
"service-unbound-check"
)
}
private val serviceUnbound = new AtomicBoolean(false)
override def apply(): Future[Boolean] =
Future.successful(cluster.selfMember.status match {
case MemberStatus.Up => !serviceUnbound.get()
case _ => false
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment