fix(redis): simplify refreshRedisHeartbeat logic and ensure proper error handling
Build & Test (NowChessSystems) TeamCity build failed

This commit is contained in:
2026-05-05 08:24:10 +02:00
parent 6e0fd9523e
commit 1813ea1d2d
@@ -173,36 +173,36 @@ class InstanceHeartbeatService:
} }
private def refreshRedisHeartbeat(): Unit = private def refreshRedisHeartbeat(): Unit =
if !redisHeartbeatPending.compareAndSet(false, true) then return if redisHeartbeatPending.compareAndSet(false, true) then
try try
val key = s"$redisPrefix:instances:$instanceId" val key = s"$redisPrefix:instances:$instanceId"
val metadata = Map( val metadata = Map(
"instanceId" -> instanceId, "instanceId" -> instanceId,
"hostname" -> getHostname, "hostname" -> getHostname,
"httpPort" -> httpPort, "httpPort" -> httpPort,
"grpcPort" -> grpcPort, "grpcPort" -> grpcPort,
"subscriptionCount" -> subscriptionCount, "subscriptionCount" -> subscriptionCount,
"localCacheSize" -> localCacheSize, "localCacheSize" -> localCacheSize,
"lastHeartbeat" -> java.time.Instant.now().toString, "lastHeartbeat" -> java.time.Instant.now().toString,
"state" -> "HEALTHY", "state" -> "HEALTHY",
)
val json = mapper.writeValueAsString(metadata)
reactiveRedis
.value(classOf[String])
.setex(key, 5L, json)
.subscribe()
.`with`(
_ => redisHeartbeatPending.set(false),
(ex: Throwable) =>
redisHeartbeatPending.set(false)
log.warnf(ex, "Failed to refresh Redis heartbeat"),
) )
catch
case ex: Exception => val json = mapper.writeValueAsString(metadata)
redisHeartbeatPending.set(false) reactiveRedis
log.warnf(ex, "Failed to serialize Redis heartbeat metadata") .value(classOf[String])
.setex(key, 5L, json)
.subscribe()
.`with`(
_ => redisHeartbeatPending.set(false),
(ex: Throwable) =>
redisHeartbeatPending.set(false)
log.warnf(ex, "Failed to refresh Redis heartbeat"),
)
catch
case ex: Exception =>
redisHeartbeatPending.set(false)
log.warnf(ex, "Failed to serialize Redis heartbeat metadata")
private def getHostname: String = private def getHostname: String =
try InetAddress.getLocalHost.getHostName try InetAddress.getLocalHost.getHostName