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 <[email protected]>
  • Loading branch information
Khoyo authored and ElysaSrc committed Oct 11, 2024
1 parent 7360bbe commit 5f771d6
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? = null

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:[email protected]: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 5f771d6

Please sign in to comment.