refactor: improve code formatting and readability

This commit is contained in:
Janis Eccarius
2026-05-31 17:03:21 +02:00
committed by Lala, Shahd
parent 4b2f3a256e
commit ad2cb7431c
@@ -32,16 +32,17 @@ class GameWritebackStreamListener:
private val log = Logger.getLogger(classOf[GameWritebackStreamListener]) private val log = Logger.getLogger(classOf[GameWritebackStreamListener])
private val groupName = "store-writeback" private val groupName = "store-writeback"
private def streamKey = s"${redisConfig.prefix}:game-writeback" private def streamKey = s"${redisConfig.prefix}:game-writeback"
private def dlqKey = s"${redisConfig.prefix}:game-writeback-dlq" private def dlqKey = s"${redisConfig.prefix}:game-writeback-dlq"
private val maxRetries = 3 private val maxRetries = 3
private val consumerId = UUID.randomUUID().toString private val consumerId = UUID.randomUUID().toString
@PostConstruct @PostConstruct
def startListening(): Unit = def startListening(): Unit =
createGroupIfAbsent() createGroupIfAbsent()
executor.submit(new Runnable: executor.submit(
def run(): Unit = pollLoop() new Runnable:
def run(): Unit = pollLoop(),
) )
log.infof("Started listening to game-writeback stream (consumer=%s)", consumerId) log.infof("Started listening to game-writeback stream (consumer=%s)", consumerId)
@@ -54,13 +55,15 @@ class GameWritebackStreamListener:
private def pollLoop(): Unit = private def pollLoop(): Unit =
while true do while true do
Try { Try {
val messages = redis.stream(classOf[String]).xreadgroup( val messages = redis
groupName, .stream(classOf[String])
consumerId, .xreadgroup(
streamKey, groupName,
">", consumerId,
new XReadGroupArgs().count(10).block(java.time.Duration.ofSeconds(2)), streamKey,
) ">",
new XReadGroupArgs().count(10).block(java.time.Duration.ofSeconds(2)),
)
Option(messages).foreach(_.forEach(msg => handleMessage(msg))) Option(messages).foreach(_.forEach(msg => handleMessage(msg)))
} match } match
case Failure(ex) => log.warnf(ex, "Error in writeback poll loop") case Failure(ex) => log.warnf(ex, "Error in writeback poll loop")