fix: clean up code formatting and improve error handling in gRPC server and failover service
Build & Test (NowChessSystems) TeamCity build failed
Build & Test (NowChessSystems) TeamCity build failed
This commit is contained in:
+2
-1
@@ -127,7 +127,8 @@ class CoordinatorGrpcServer extends CoordinatorServiceGrpc.CoordinatorServiceImp
|
||||
_ =>
|
||||
val response = DrainInstanceResponse.newBuilder().setGamesMigrated(gamesBefore).build()
|
||||
responseObserver.onNext(response)
|
||||
responseObserver.onCompleted(),
|
||||
responseObserver.onCompleted()
|
||||
,
|
||||
ex =>
|
||||
log.warnf(ex, "Drain failed for %s", instanceId)
|
||||
responseObserver.onError(ex),
|
||||
|
||||
+6
-3
@@ -122,14 +122,17 @@ class FailoverService:
|
||||
log.infof("Cleaned up games set for instance %s", instanceId)
|
||||
|
||||
private def waitForHealthyInstanceAsync(): Uni[InstanceMetadata] =
|
||||
Uni.createFrom().deferred(() =>
|
||||
Uni
|
||||
.createFrom()
|
||||
.deferred(() =>
|
||||
instanceRegistry.getAllInstances
|
||||
.filter(_.state == "HEALTHY")
|
||||
.sortBy(_.subscriptionCount)
|
||||
.headOption match
|
||||
case Some(inst) => Uni.createFrom().item(inst)
|
||||
case None => Uni.createFrom().failure(new RuntimeException("no healthy instance"))
|
||||
).onFailure()
|
||||
case None => Uni.createFrom().failure(new RuntimeException("no healthy instance")),
|
||||
)
|
||||
.onFailure()
|
||||
.retry()
|
||||
.withBackOff(Duration.ofMillis(500))
|
||||
.expireIn(config.failoverWaitTimeout.toMillis)
|
||||
|
||||
+3
-5
@@ -133,8 +133,7 @@ class HealthMonitor:
|
||||
action match
|
||||
case Watcher.Action.DELETED =>
|
||||
handlePodGone(pod)
|
||||
case Watcher.Action.MODIFIED
|
||||
if Option(pod.getMetadata.getDeletionTimestamp).isDefined =>
|
||||
case Watcher.Action.MODIFIED if Option(pod.getMetadata.getDeletionTimestamp).isDefined =>
|
||||
handlePodTerminating(pod)
|
||||
case _ => ()
|
||||
|
||||
@@ -142,11 +141,10 @@ class HealthMonitor:
|
||||
Option(cause).foreach { ex =>
|
||||
log.warnf(ex, "Pod watch closed, restarting")
|
||||
startPodWatch()
|
||||
}
|
||||
},
|
||||
)
|
||||
log.info("Pod watch started")
|
||||
catch
|
||||
case ex: Exception => log.warnf(ex, "Failed to start pod watch")
|
||||
catch case ex: Exception => log.warnf(ex, "Failed to start pod watch")
|
||||
|
||||
private def isPodReady(pod: Pod): Boolean =
|
||||
Option(pod.getStatus)
|
||||
|
||||
Reference in New Issue
Block a user