livery_health (livery v0.2.0)

View Source

Health and readiness handlers.

live/0 is a liveness probe - it always answers 200 {"status":"ok"} (the process is up). ready/1 is a readiness probe - it runs a list of named checks and answers 200 when all pass, or 503 listing the failed checks. Mount them on routes:

R1 = livery_router:add('GET', <<"/healthz">>, livery_health:live(), #{}, R0),
R2 = livery_router:add(
    '_GET', <<"/readyz">>,
    livery_health:ready([{<<"db">>, fun () -> my_db:ping() end}]),
    #{}, R1
).

A check is {Name, fun(() -> ok | {error, term()})}; any non-ok return or a raised exception counts as failed. Checks run synchronously in the request process, so keep them fast.

Summary

Functions

Liveness handler: always 200 {"status":"ok"}.

Readiness handler: 200 when every check passes, else 503.

Types

check()

-type check() :: {binary(), fun(() -> ok | {error, term()})}.

Functions

live()

-spec live() -> livery_middleware:handler().

Liveness handler: always 200 {"status":"ok"}.

ready(Checks)

-spec ready([check()]) -> livery_middleware:handler().

Readiness handler: 200 when every check passes, else 503.