fix(redis): simplify refreshRedisHeartbeat logic and ensure proper error handling
Build & Test (NowChessSystems) TeamCity build failed
Build & Test (NowChessSystems) TeamCity build failed
This commit is contained in:
+28
-28
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user