2.1 KiB · text 5af55d9
defmodule GitGud.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
@impl true
def start(_type, _args) do
# Route error-level logs + process crash reports (incl. LiveView and
# GenServer terminations) to Sentry. No-ops when SENTRY_DSN is unset.
:logger.add_handler(:sentry_handler, Sentry.LoggerHandler, %{
level: :error,
config: %{metadata: [:file, :line], capture_log_messages: true}
})
topologies = Application.get_env(:libcluster, :topologies, [])
children =
[
GitGudWeb.Telemetry,
GitGud.Repo,
{DNSCluster, query: Application.get_env(:git_gud, :dns_cluster_query) || :ignore}
] ++
cluster_children(topologies) ++
[
{Phoenix.PubSub, name: GitGud.PubSub},
# Multilevel supervises its L1 + L2 children itself per the
# `levels:` config — listing them here would double-start.
GitGud.Cache,
{Oban, Application.fetch_env!(:git_gud, Oban)},
GitGud.Federation.RateLimiter,
GitGud.Ssh.Server,
GitGudWeb.Endpoint
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: GitGud.Supervisor]
Supervisor.start_link(children, opts)
end
# When `:libcluster` has no topology configured (dev / test / single-
# node prod), skip Cluster.Supervisor entirely. In a multi-replica
# prod with the Kubernetes topology defined in runtime.exs, libcluster
# discovers peer pods and connects them; once the cluster forms,
# `GitGud.Cache.L2`'s Replicated adapter joins its pg group across
# nodes.
defp cluster_children([]), do: []
defp cluster_children(topologies) do
[{Cluster.Supervisor, [topologies, [name: GitGud.ClusterSupervisor]]}]
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
@impl true
def config_change(changed, _new, removed) do
GitGudWeb.Endpoint.config_change(changed, removed)
:ok
end
end