lintel 0.2.0
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
lintel::ReadinessRegistry Class Reference

#include <ReadinessRegistry.h>

Classes

struct  CheckResult
 

Public Types

using Check = std::function< bool(std::string &)>
 

Public Member Functions

void registerCheck (std::string name, Check check)
 
void clear ()
 
std::vector< CheckResult > run () const
 

Static Public Member Functions

static ReadinessRegistry & instance ()
 

Detailed Description

Process-wide registry of the dependency checks behind GET /ready.

Liveness (GET /health) is answered by the endpoint itself and must never consult a dependency. Readiness is different: it reports whether the process is able to do its work, so it has to ask the dependencies (database, shared memory, ...). The component that owns such a dependency registers a named check once during startup; the HTTP layer runs every registered check per readiness request and turns the results into 200 or 503.

The registry is a process-wide singleton (the same pattern LoggerService uses): checks are registered from components in different layers (persistence plugins, feature services) that share no DI scope with the HTTP server, which is built from configuration alone. Registering a name that is already present replaces the old check, so a re-initialization stays idempotent.

Thread safety: registerCheck(), clear() and run() may be called from any thread. The checks themselves run outside the registry lock - a slow dependency must not block other components from registering, and a check may take locks of its own subsystem.

Member Typedef Documentation

◆ Check

using lintel::ReadinessRegistry::Check = std::function<bool(std::string &)>

A dependency check.

Parameters
detailset to a human readable reason when returning false
Returns
true when the dependency is ready

Member Function Documentation

◆ clear()

void lintel::ReadinessRegistry::clear ( )

Remove every registered check (used by tests).

◆ instance()

static ReadinessRegistry & lintel::ReadinessRegistry::instance ( )
static
Returns
the process-wide registry instance

◆ registerCheck()

void lintel::ReadinessRegistry::registerCheck ( std::string  name,
Check  check 
)

Register a named check; an existing check of the same name is replaced.

Parameters
nameunique name, reported as JSON key by GET /ready
checkthe dependency check

◆ run()

std::vector< CheckResult > lintel::ReadinessRegistry::run ( ) const

Run all registered checks in registration order.

A check that throws counts as failed with the exception message as detail.

Returns
one result per registered check

The documentation for this class was generated from the following file: