LemonCore.Runtime.Health (lemon_core v0.1.0)

View Source

Health and readiness checks for the Lemon runtime.

Provides functions to probe whether a Lemon runtime is already running on a given port and to report the current health of running applications. This replaces the curl -sS -m 2 http://localhost:$PORT/healthz check that previously lived in bin/lemon.

Usage

# Check if another instance is already running
LemonCore.Runtime.Health.running?(4040)
# => true | false

# Wait for startup
{:ok, :healthy} = LemonCore.Runtime.Health.await(4040, timeout_ms: 10_000)

# Report local readiness
LemonCore.Runtime.Health.status()
# => %{status: :ok, apps: [...], missing: []}

Summary

Functions

Polls port until the health endpoint returns HTTP 200 or timeout_ms elapses.

Returns true if a Lemon control-plane process is already healthy on port.

Returns the health status of the locally running Lemon apps.

Functions

await(port, opts \\ [])

@spec await(
  pos_integer(),
  keyword()
) :: {:ok, :healthy} | {:error, :timeout}

Polls port until the health endpoint returns HTTP 200 or timeout_ms elapses.

Returns {:ok, :healthy} on success or {:error, :timeout} on failure.

running?(port, opts \\ [])

@spec running?(
  pos_integer(),
  keyword()
) :: boolean()

Returns true if a Lemon control-plane process is already healthy on port.

Uses a plain TCP-level HTTP request to avoid depending on an HTTP client library at startup. Times out after timeout_ms (default: 2 000 ms).

Options

  • :timeout_ms - how long to wait in milliseconds (default: 2 000)
  • :path - health endpoint path (default: "/healthz")

status(opts \\ [])

@spec status(keyword()) :: map()

Returns the health status of the locally running Lemon apps.

Checks that each expected app in apps is started. If no apps list is provided, returns the status for all applications currently loaded.

Return shape

%{
  status: :ok | :degraded,
  apps: [:lemon_gateway, ...],
  missing: []
}