Botica.Check.Group (Botica v2.2.0)

Copy Markdown View Source

Groups health checks into a unit that runs with a shared timeout.

A group is a named collection of check definitions with execution options (timeout_ms, parallel). It reuses Botica.Runner.Executor for execution, so per-check timeouts and crash isolation apply.

Example

group = Botica.Check.Group.new(:db, [check_db, check_cache], timeout_ms: 2_000)

results = Botica.Check.Group.run(group)
# => %{db: %Check.Result{}, cache: %Check.Result{}}

Result aggregation

as_result/2 reduces the group into a single summary result:

  • :ok — all checks passed (or no checks).
  • :error — at least one check failed.

Summary

Functions

Reduces the group results into a single Botica.Check.Result.

Creates a new group.

Runs all checks in the group.

Types

t()

@type t() :: %Botica.Check.Group{
  checks: [Botica.Types.check_def()],
  name: atom() | String.t(),
  parallel: boolean(),
  timeout_ms: non_neg_integer()
}

Functions

as_result(group, desired)

@spec as_result(t(), :ok | :error) :: Botica.Types.result()

Reduces the group results into a single Botica.Check.Result.

desired is :ok (all checks must pass) or :error (any failure flips the summary to error). Returns a summary result whose id is the group name.

new(name, checks, opts \\ [])

@spec new(atom() | String.t(), [Botica.Types.check_def()], keyword()) :: t()

Creates a new group.

Options

  • :timeout_ms — global timeout for the whole group (default 5000).
  • :parallel — run checks in parallel (default true).

run(group)

@spec run(t()) :: %{
  required(Botica.Types.check_id()) => Botica.Types.result() | term()
}

Runs all checks in the group.

Returns a map of %{check_id => Result.t()} (or %{check_id => error} for un-runnable groups).