Get server id from env

This commit is contained in:
Broks Randolfs Gailītis 2025-08-18 20:07:26 +03:00
parent 8c4377499c
commit 6da72d5801
4 changed files with 13 additions and 16 deletions

3
.gitignore vendored
View File

@ -21,3 +21,6 @@ message_server-*.tar
# Temporary files, for example, from tests. # Temporary files, for example, from tests.
/tmp/ /tmp/
# Storage
/storage/

View File

@ -1,20 +1,22 @@
defmodule MessageServer.Application do defmodule MessageServer.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application use Application
require Logger
@impl true @impl true
def start(_type, _args) do def start(_type, _args) do
server_id = get_server_id()
children = [ children = [
# Starts a worker by calling: MessageServer.Worker.start_link(arg) {MessageServer.Storage, server_id}
# {MessageServer.Worker, arg}
] ]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: MessageServer.Supervisor] opts = [strategy: :one_for_one, name: MessageServer.Supervisor]
Supervisor.start_link(children, opts) Supervisor.start_link(children, opts)
end end
@spec get_server_id() :: String.t()
def get_server_id() do
System.get_env("SERVER_ID") ||
raise "SERVER_ID is required"
end
end end

View File

@ -1,7 +0,0 @@
test_server-bob: Hello Alice!
test_server-bob: Hi Alice
test_server-bob: Hello! 🎉 Special chars: @#$%^&*()
test_server-bob: Test message
test_server-bob: First message
test_server-charlie: Second message
test_server-bob: Hello Alice!

View File

@ -1 +0,0 @@
test_server-bob: Hi Charlie