Candil.Engine.HealthPoller (Candil v3.0.0)

Copy Markdown View Source

Shared health-polling logic for engine GenServers.

Both Candil.Engine.Server and Candil.Engine.Server.External poll <base_url>/health every 5 seconds. This module provides the common probe_health/1 function and macros/clauses for the repeated handle_call(:health, ...), handle_call(:base_url, ...) and handle_info(:poll_health, ...) patterns.

Summary

Functions

Implements GenServer.handle_call/3 for :health and :base_url.

Implements the :poll_health timer message.

Returns the initial state map with healthy: false.

Returns the poll interval in milliseconds.

Probe base_url/health and return true if reachable (HTTP 200).

Functions

handle_base_url_call(state, base_url)

handle_health_call(state)

Implements GenServer.handle_call/3 for :health and :base_url.

Use from your GenServer via:

def handle_call(:health, _from, state), do: HealthPoller.handle_health_call(state)
def handle_call(:base_url, _from, state), do: HealthPoller.handle_base_url_call(state, state.base_url)

handle_poll_health(state)

Implements the :poll_health timer message.

Call from your GenServer's handle_info/2:

def handle_info(:poll_health, state), do: HealthPoller.handle_poll_health(state)

initial_state(extra \\ [])

@spec initial_state(keyword()) :: map()

Returns the initial state map with healthy: false.

poll_interval()

@spec poll_interval() :: pos_integer()

Returns the poll interval in milliseconds.

probe_health(base_url)

@spec probe_health(binary()) :: boolean()

Probe base_url/health and return true if reachable (HTTP 200).