1.5 KiB · text History 44bc4f7
defmodule CartosnapApp.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
    topologies = Application.get_env(:libcluster, :topologies, [])

    children = [
      CartosnapAppWeb.Telemetry,
      CartosnapApp.Repo,
      {DNSCluster, query: Application.get_env(:cartosnap_app, :dns_cluster_query) || :ignore},
      cluster_child(topologies),
      {Phoenix.PubSub, name: CartosnapApp.PubSub},
      CartosnapAppWeb.Presence,
      {Oban, Application.fetch_env!(:cartosnap_app, Oban)},
      # Start to serve requests, typically the last entry
      CartosnapAppWeb.Endpoint
    ]

    # See https://elixir.hexdocs.pm/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: CartosnapApp.Supervisor]
    Supervisor.start_link(Enum.reject(children, &is_nil/1), opts)
  end

  # libcluster only runs where a topology is configured (prod, via
  # runtime.exs); in dev and test there is no Cluster.Supervisor at all.
  defp cluster_child([]), do: nil

  defp cluster_child(topologies),
    do: {Cluster.Supervisor, [topologies, [name: CartosnapApp.ClusterSupervisor]]}

  # Tell Phoenix to update the endpoint configuration
  # whenever the application is updated.
  @impl true
  def config_change(changed, _new, removed) do
    CartosnapAppWeb.Endpoint.config_change(changed, removed)
    :ok
  end
end