Goodoo.Checker behaviour (Goodoo v0.1.0) View Source

Behaviour for implementing a checker.

Goodoo aims to makes it simple to create a checker. There are 2 callbacks that require implementation.

defmodule MyHTTPChecker do
  @behaviour Goodoo.Checker

  @impl true
  def init(options) do
    options
  end

  @impl true
  def perform(options) do
    case HTTPClient.get("https://external-service.net/ping") do
      {:ok, 200, "OK"} ->
        :healthy

      {:ok, 503, "Service unavailable"} ->
        :unhealthy

      {:error, :timeout} ->
        :degraded
    end
  end
end

Configure it in your Goodoo module:

checkers = %{
  "external_service" => {MyHTTPChecker, []}
}

children = [
  ...,
  {MyHealthCheck, checkers}
]

Supervisor.start_link(children, strategy: :one_for_one, name: MyApp)

Please check out Goodoo.Checker.Redix or Goodoo.Checker.EctoSQL to see a working example.

Link to this section Summary

Callbacks

Initiates the checker with the given options.

Performs the check.

Link to this section Types

Specs

checker_state() :: any()

Specs

health_state() :: :healthy | :unhealthy | :degraded | :init

Specs

name() :: String.t()

Link to this section Callbacks

Specs

init(options :: Keyword.t()) :: checker_state()

Initiates the checker with the given options.

Specs

perform(checker_state()) :: health_state()

Performs the check.