feat(tournament): seed external server registry from env var on startup
Build & Test (NowChessSystems) TeamCity build was queued
Build & Test (NowChessSystems) TeamCity build was queued
TOURNAMENT_EXTERNAL_SERVERS (comma-separated URLs) is loaded into TournamentServerRegistry at startup so the bot can park on all servers and replication targets are known without manual API calls after each restart. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,7 @@ nowchess:
|
|||||||
internal:
|
internal:
|
||||||
secret: 123abc
|
secret: 123abc
|
||||||
tournament:
|
tournament:
|
||||||
service-url: http://localhost:8086
|
service-url: http://localhost:8088
|
||||||
|
|
||||||
"%deployed":
|
"%deployed":
|
||||||
quarkus:
|
quarkus:
|
||||||
@@ -52,4 +52,4 @@ nowchess:
|
|||||||
internal:
|
internal:
|
||||||
secret: ${INTERNAL_SECRET}
|
secret: ${INTERNAL_SECRET}
|
||||||
tournament:
|
tournament:
|
||||||
service-url: ${TOURNAMENT_SERVICE_URL:http://localhost:8086}
|
service-url: ${TOURNAMENT_SERVICE_URL:http://localhost:8088}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ nowchess:
|
|||||||
secret: ${INTERNAL_SECRET:123abc}
|
secret: ${INTERNAL_SECRET:123abc}
|
||||||
tournament:
|
tournament:
|
||||||
self-url: ""
|
self-url: ""
|
||||||
|
external-servers: ""
|
||||||
|
|
||||||
mp:
|
mp:
|
||||||
jwt:
|
jwt:
|
||||||
@@ -51,6 +52,7 @@ mp:
|
|||||||
nowchess:
|
nowchess:
|
||||||
tournament:
|
tournament:
|
||||||
self-url: ${TOURNAMENT_SELF_URL:}
|
self-url: ${TOURNAMENT_SELF_URL:}
|
||||||
|
external-servers: ${TOURNAMENT_EXTERNAL_SERVERS:}
|
||||||
|
|
||||||
"%test":
|
"%test":
|
||||||
quarkus:
|
quarkus:
|
||||||
|
|||||||
+13
-1
@@ -1,17 +1,29 @@
|
|||||||
package de.nowchess.tournament.service
|
package de.nowchess.tournament.service
|
||||||
|
|
||||||
import de.nowchess.tournament.dto.ExternalTournamentServer
|
import de.nowchess.tournament.dto.ExternalTournamentServer
|
||||||
|
import jakarta.annotation.PostConstruct
|
||||||
import jakarta.enterprise.context.ApplicationScoped
|
import jakarta.enterprise.context.ApplicationScoped
|
||||||
import java.util.UUID
|
import org.eclipse.microprofile.config.inject.ConfigProperty
|
||||||
|
import java.util.{Optional, UUID}
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import scala.jdk.CollectionConverters.*
|
import scala.jdk.CollectionConverters.*
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
class TournamentServerRegistry:
|
class TournamentServerRegistry:
|
||||||
|
|
||||||
|
@ConfigProperty(name = "nowchess.tournament.external-servers")
|
||||||
|
var externalServers: Optional[String] = scala.compiletime.uninitialized
|
||||||
|
|
||||||
private val servers = new ConcurrentHashMap[String, ExternalTournamentServer]()
|
private val servers = new ConcurrentHashMap[String, ExternalTournamentServer]()
|
||||||
private val tournaments = new ConcurrentHashMap[String, String]()
|
private val tournaments = new ConcurrentHashMap[String, String]()
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
def init(): Unit =
|
||||||
|
if externalServers.isPresent then
|
||||||
|
externalServers.get().split(",").map(_.trim).filter(_.nonEmpty).foreach { url =>
|
||||||
|
register(url, url)
|
||||||
|
}
|
||||||
|
|
||||||
def register(label: String, url: String): ExternalTournamentServer =
|
def register(label: String, url: String): ExternalTournamentServer =
|
||||||
val id = UUID.randomUUID().toString
|
val id = UUID.randomUUID().toString
|
||||||
val server = ExternalTournamentServer(id, label, url.stripSuffix("/"))
|
val server = ExternalTournamentServer(id, label, url.stripSuffix("/"))
|
||||||
|
|||||||
Reference in New Issue
Block a user