fix: clean up code formatting and improve error handling in gRPC server and failover service
Build & Test (NowChessSystems) TeamCity build failed

This commit is contained in:
2026-05-13 13:16:22 +02:00
parent 2b04d7fa71
commit ad9495afa3
3 changed files with 15 additions and 13 deletions
@@ -127,7 +127,8 @@ class CoordinatorGrpcServer extends CoordinatorServiceGrpc.CoordinatorServiceImp
_ => _ =>
val response = DrainInstanceResponse.newBuilder().setGamesMigrated(gamesBefore).build() val response = DrainInstanceResponse.newBuilder().setGamesMigrated(gamesBefore).build()
responseObserver.onNext(response) responseObserver.onNext(response)
responseObserver.onCompleted(), responseObserver.onCompleted()
,
ex => ex =>
log.warnf(ex, "Drain failed for %s", instanceId) log.warnf(ex, "Drain failed for %s", instanceId)
responseObserver.onError(ex), responseObserver.onError(ex),
@@ -122,14 +122,17 @@ class FailoverService:
log.infof("Cleaned up games set for instance %s", instanceId) log.infof("Cleaned up games set for instance %s", instanceId)
private def waitForHealthyInstanceAsync(): Uni[InstanceMetadata] = private def waitForHealthyInstanceAsync(): Uni[InstanceMetadata] =
Uni.createFrom().deferred(() => Uni
instanceRegistry.getAllInstances .createFrom()
.filter(_.state == "HEALTHY") .deferred(() =>
.sortBy(_.subscriptionCount) instanceRegistry.getAllInstances
.headOption match .filter(_.state == "HEALTHY")
.sortBy(_.subscriptionCount)
.headOption match
case Some(inst) => Uni.createFrom().item(inst) case Some(inst) => Uni.createFrom().item(inst)
case None => Uni.createFrom().failure(new RuntimeException("no healthy instance")) case None => Uni.createFrom().failure(new RuntimeException("no healthy instance")),
).onFailure() )
.onFailure()
.retry() .retry()
.withBackOff(Duration.ofMillis(500)) .withBackOff(Duration.ofMillis(500))
.expireIn(config.failoverWaitTimeout.toMillis) .expireIn(config.failoverWaitTimeout.toMillis)
@@ -133,8 +133,7 @@ class HealthMonitor:
action match action match
case Watcher.Action.DELETED => case Watcher.Action.DELETED =>
handlePodGone(pod) handlePodGone(pod)
case Watcher.Action.MODIFIED case Watcher.Action.MODIFIED if Option(pod.getMetadata.getDeletionTimestamp).isDefined =>
if Option(pod.getMetadata.getDeletionTimestamp).isDefined =>
handlePodTerminating(pod) handlePodTerminating(pod)
case _ => () case _ => ()
@@ -142,11 +141,10 @@ class HealthMonitor:
Option(cause).foreach { ex => Option(cause).foreach { ex =>
log.warnf(ex, "Pod watch closed, restarting") log.warnf(ex, "Pod watch closed, restarting")
startPodWatch() startPodWatch()
} },
) )
log.info("Pod watch started") log.info("Pod watch started")
catch catch case ex: Exception => log.warnf(ex, "Failed to start pod watch")
case ex: Exception => log.warnf(ex, "Failed to start pod watch")
private def isPodReady(pod: Pod): Boolean = private def isPodReady(pod: Pod): Boolean =
Option(pod.getStatus) Option(pod.getStatus)