Last active
April 18, 2021 20:18
-
-
Save lpeppe/e1818833645ba6f9b83bd7fadba1fc26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule PhxHealthcheck.Healthcheck.Supervisor do | |
alias PhxHealthcheck.Healthcheck.Worker | |
use Supervisor | |
def start_link(init_arg) do | |
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__) | |
end | |
@impl true | |
def init(_init_arg) do | |
children = | |
:phx_healthcheck | |
|> Application.get_env(:healthcheck, []) | |
|> Keyword.get(:services, []) | |
|> Enum.map(fn {service, opts} -> | |
refresh_interval = Keyword.fetch!(opts, :refresh_interval) | |
Supervisor.child_spec({Worker, [service, refresh_interval]}, id: service) | |
end) | |
Supervisor.init(children, strategy: :one_for_one) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment