Skip to content

Commit

Permalink
core: add the posibility to use hostname as WORKEY_ID
Browse files Browse the repository at this point in the history
This is useful when using keda or other autoscalers, as they won't
support assigning WORKER_IDs.

Signed-off-by: Younes Khoudli <younes.khoudli@epita.fr>
  • Loading branch information
Khoyo authored and ElysaSrc committed Oct 11, 2024
1 parent 1985524 commit 2b23321
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/src/main/java/fr/sncf/osrd/cli/WorkerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ class WorkerCommand : CliCommand {
private var editoastAuthorization: String = "x-osrd-core"

val WORKER_ID: String?
val WORKER_ID_USE_HOSTNAME: String?
val WORKER_KEY: String?
val WORKER_AMQP_URI: String
val WORKER_POOL: String
val WORKER_REQUESTS_QUEUE: String
val WORKER_ACTIVITY_EXCHANGE: String

init {
WORKER_ID = System.getenv("WORKER_ID")
WORKER_ID_USE_HOSTNAME = System.getenv("WORKER_ID_USE_HOSTNAME")
WORKER_KEY = System.getenv("WORKER_KEY")
WORKER_AMQP_URI =
System.getenv("WORKER_AMQP_URI") ?: "amqp://osrd:password@127.0.0.1:5672/%2f"
Expand All @@ -55,6 +56,18 @@ class WorkerCommand : CliCommand {
System.getenv("WORKER_REQUESTS_QUEUE") ?: "$WORKER_POOL-req-$WORKER_KEY"
WORKER_ACTIVITY_EXCHANGE =
System.getenv("WORKER_ACTIVITY_EXCHANGE") ?: "$WORKER_POOL-activity-xchg"

WORKER_ID =
if (
WORKER_ID_USE_HOSTNAME == null ||
WORKER_ID_USE_HOSTNAME == "" ||
WORKER_ID_USE_HOSTNAME == "0" ||
WORKER_ID_USE_HOSTNAME.lowercase() == "false"
) {
System.getenv("WORKER_ID")
} else {
java.net.InetAddress.getLocalHost().hostName
}
}

override fun run(): Int {
Expand Down

0 comments on commit 2b23321

Please sign in to comment.