HeartCheck behaviour (heartcheck v0.4.3) View Source

Define your own checks using this macro:


defmodule MyHeart do
  use HeartCheck, timeout: 2000 # 3000 is default

  add :redis do
    # TODO: do some actual checks here
    :ok
  end

  add :cas do
    # TODO: do some actual checks here
    :timer.sleep(2000)
    {:error, "something went wrong"}
  end

  # you can use modules that implement the `HeartCheck.Check` behaviour too:
  add :module_check, MyTestModule
end

In the example above, MyTestModule can be something like:

defmodule MyTestModule do
  @behaviour HeartCheck.Check

  @impl HeartCheck.Check
  def call do
    # TODO: perform some actual checks here
    :ok
  end
end

Link to this section Summary

Types

Return format for heartcheck checks

Functions

Adds HeartCheck support for your module.

Adds a check to your heartcheck module.

Add firewall checks to your external services using a keyword list.

Add firewall checks to your external services using a list with name and url.

Callbacks

Returns the list of the names of checks performed by this HeartCheck module

Performs the check identifier by name

Returns the timeout in milliseconds for running all the checks

Link to this section Types

Specs

result() :: :ok | {:error, String.t()} | :error

Return format for heartcheck checks

Link to this section Functions

Link to this macro

__using__(opts)

View Source (macro)

Specs

__using__(Keyword.t()) :: Macro.t()

Adds HeartCheck support for your module.

You may define the timeout (in milliseconds) for the overall checks using the timeout option.

Link to this macro

add(check, mod)

View Source (macro)

Specs

add(:atom | String.t(), [{:do, (() -> result())}] | HeartCheck.Check) ::
  Macro.t()

Adds a check to your heartcheck module.

The check is identified by name (will be converted to an atom).

The check itself may be described by a function in the do block or in an external module.

The function or external module return value must conform to the result type by returning either :ok, :error or {:error, String.t}

Link to this macro

firewall(opts)

View Source (macro)

Specs

firewall(Keyword.t()) :: Macro.t()

Add firewall checks to your external services using a keyword list.

Keys are used for the check names and the values are evaluated in runtime to obtain the url to check. Options such as timeout can be merged with the list of URLs to check.

Link to this macro

firewall(name, url, opts \\ [])

View Source (macro)

Specs

firewall(String.t() | atom(), String.t() | term(), Keyword.t()) :: Macro.t()

Add firewall checks to your external services using a list with name and url.

Optionally accepts a keyword list of options. Currently, the only option available is timeout.

Link to this section Callbacks

Specs

checks() :: [atom()]

Returns the list of the names of checks performed by this HeartCheck module

Specs

perform_check(name :: atom()) :: result()

Performs the check identifier by name

Specs

timeout() :: non_neg_integer()

Returns the timeout in milliseconds for running all the checks