who_need_help/lib/who_need_help/application.ex

46 lines
1.4 KiB
Elixir

defmodule WhoNeedHelp.Application do
# See https://elixir.hexdocs.pm/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
@impl true
def start(_type, _args) do
common_children = [
WhoNeedHelpWeb.Telemetry,
WhoNeedHelp.Repo,
{DNSCluster, query: Application.get_env(:who_need_help, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: WhoNeedHelp.PubSub}
]
oban_config = Application.fetch_env!(:who_need_help, Oban)
oban_client_config = Keyword.merge(oban_config, queues: [], plugins: [], peer: false)
role_children =
case Application.fetch_env!(:who_need_help, :app_role) do
:web -> [{Oban, oban_client_config}, WhoNeedHelpWeb.Presence, WhoNeedHelpWeb.Endpoint]
:worker -> [{Oban, oban_config}]
:migrate -> [{Oban, oban_client_config}]
end
children = common_children ++ role_children
# See https://elixir.hexdocs.pm/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: WhoNeedHelp.Supervisor]
Supervisor.start_link(children, opts)
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
@impl true
def config_change(changed, _new, removed) do
if Application.get_env(:who_need_help, :app_role) == :web do
WhoNeedHelpWeb.Endpoint.config_change(changed, removed)
end
:ok
end
end