Skip to content

Instantly share code, notes, and snippets.

@lpeppe
Created April 20, 2021 19:41
Show Gist options
  • Save lpeppe/96d3e0afc7be70eec00f2ac6a4cbcd1b to your computer and use it in GitHub Desktop.
Save lpeppe/96d3e0afc7be70eec00f2ac6a4cbcd1b to your computer and use it in GitHub Desktop.
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