health
The pod's datasource health checks and its Hub heartbeat.
Also the session token refresh and the event-loop lag watchdog, the two tickers that exist to keep the heartbeat honest.
Classes
PodHealthMonitor
class PodHealthMonitor( ctx: PodContext, *, ehr: EHRStatus, is_busy: Callable[[], bool], bootstrap_cluster_id: str | None,):Datasource health, the Hub heartbeat, token refresh and loop lag.
Arguments
ctx: The pod's identity and services.ehr: What the heartbeat reports about the pod's EHR connection.is_busy: Whether the pod is executing a task, read per heartbeat.bootstrap_cluster_id: The cluster ID to report while the Hub has not assigned one.
Variables
cached_datasource_health : list[dict[str, str]] | None- The last health check's result, orNonebefore the first.
Methods
collect_datasource_health
def collect_datasource_health(self) ‑> list[dict[str, str]]:Collect health status for all registered datasources.
Runs accessibility checks in parallel using a thread pool with timeouts to prevent slow datasources from blocking the heartbeat.
Returns List of health status dicts, each containing:
- name: datasource name
- status: "healthy", "unhealthy", or "unknown"
- error_code: (optional) error code if unhealthy/unknown
- message: (optional) error message if available
datasource_health_tick
async def datasource_health_tick(self) ‑> None:Check datasource health and update cached status.
heartbeat_tick
async def heartbeat_tick(self) ‑> None:Send a pod heartbeat to the hub.
loop_lag_tick
async def loop_lag_tick(self) ‑> None:Warn when work on the pod's event loop is starving everything else.
Sleeps a known interval and reports how much longer than that it took. A pod that cannot schedule this tick cannot send its heartbeat either, and the hub then shows every dataset on the pod as offline — so an overshoot is worth naming the loop's tasks for.
Diagnostic only: it never acts on what it finds. An overshoot is not proof of a blocked loop (a suspended laptop looks the same), which is why the threshold sits well above the heartbeat interval.
Each overshoot is also sent to Datadog, so how often a site's loop stalls, and for how long, can be read without asking for its log.
set_cached_datasource_health
def set_cached_datasource_health(self, value: list[dict[str, str]] | None) ‑> None:Replace the cached health with a freshly collected result.
An atomic reference swap under CPython's GIL, so the heartbeat reading it from a worker thread needs no lock.
set_metadata_recorder
def set_metadata_recorder(self, recorder: DatasourceMetadataRecorder) ‑> None:Bind the indexing coordinator, which is built after this monitor.
Pod calls this once during construction, before start_async, so no
tick can run without it.
token_refresh_tick
async def token_refresh_tick(self) ‑> None:Keep the Bitfount session's token fresh.
Reading hub_request_headers refreshes the token when it is within
_TOKEN_EXPIRY_BUFFER_SECONDS of expiry, under the session's
reauthentication lock. That refresh used to happen only as a side effect
of the heartbeat's hub call, which heartbeat_tick skips whenever there
is no datasource health to report - so a pod whose health cache never
populated stopped refreshing entirely, and the mailbox listener was left
holding a token that expired underneath it.
Never raises: _repeat does not guard the coroutines it schedules, so an
exception here would silently kill the ticker and take token refresh with
it - the failure this exists to prevent.
trigger_heartbeat
def trigger_heartbeat(self) ‑> None:Send an immediate heartbeat so the hub reflects datasource changes.