Created
April 20, 2021 19:41
-
-
Save lpeppe/96d3e0afc7be70eec00f2ac6a4cbcd1b 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 PhxHealthcheckWeb.HealthcheckController do | |
use PhxHealthcheckWeb, :controller | |
alias PhxHealthcheck.Healthcheck | |
def status(conn, _params) do | |
monitorable_services = | |
:phx_healthcheck | |
|> Application.get_env(:healthcheck, services: []) | |
|> Keyword.fetch!(:services) | |
services_status = | |
monitorable_services | |
|> Enum.map(&fetch_service_status!/1) | |
|> Enum.into(%{}) | |
json(conn, services_status) | |
end | |
defp fetch_service_status!({service, opts}) do | |
service_name = Keyword.fetch!(opts, :name) | |
service_status = Healthcheck.get_service_status(service) | |
{service_name, service_status} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment