Get server id from env
This commit is contained in:
parent
8c4377499c
commit
6da72d5801
3
.gitignore
vendored
3
.gitignore
vendored
@ -21,3 +21,6 @@ message_server-*.tar
|
||||
|
||||
# Temporary files, for example, from tests.
|
||||
/tmp/
|
||||
|
||||
# Storage
|
||||
/storage/
|
||||
|
||||
@ -1,20 +1,22 @@
|
||||
defmodule MessageServer.Application do
|
||||
# See https://hexdocs.pm/elixir/Application.html
|
||||
# for more information on OTP Applications
|
||||
@moduledoc false
|
||||
|
||||
use Application
|
||||
require Logger
|
||||
|
||||
@impl true
|
||||
def start(_type, _args) do
|
||||
server_id = get_server_id()
|
||||
|
||||
children = [
|
||||
# Starts a worker by calling: MessageServer.Worker.start_link(arg)
|
||||
# {MessageServer.Worker, arg}
|
||||
{MessageServer.Storage, server_id}
|
||||
]
|
||||
|
||||
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||
# for other strategies and supported options
|
||||
opts = [strategy: :one_for_one, name: MessageServer.Supervisor]
|
||||
Supervisor.start_link(children, opts)
|
||||
end
|
||||
|
||||
@spec get_server_id() :: String.t()
|
||||
def get_server_id() do
|
||||
System.get_env("SERVER_ID") ||
|
||||
raise "SERVER_ID is required"
|
||||
end
|
||||
end
|
||||
|
||||
@ -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!
|
||||
@ -1 +0,0 @@
|
||||
test_server-bob: Hi Charlie
|
||||
Loading…
x
Reference in New Issue
Block a user