livery_grpc_health_store (livery_grpc v0.1.1)

View Source

Serving-status store behind livery_grpc_health, with watch subscriptions.

Holds the per-service status and the set of watchers. Setting a status pushes a {grpc_health_watch, Service, Status} message to every watcher of that service, which is how Watch streams live updates. Watchers are monitored, so a disconnected watcher is dropped automatically.

The empty service name (<<>>) is the overall server status and defaults to SERVING; a named service that was never set is unknown.

Summary

Functions

Set a service's serving status and notify its watchers.

The current status for Check: {ok, Status}, or not_found for a named service that was never registered (the overall server defaults to SERVING).

Register the caller as a watcher of Service and return the current status to emit first. A named unknown service resolves to SERVICE_UNKNOWN (Watch keeps the stream open rather than erroring).

Types

serving_status()

-type serving_status() :: 'UNKNOWN' | 'SERVING' | 'NOT_SERVING' | 'SERVICE_UNKNOWN'.

Functions

code_change(Old, State, Extra)

-spec code_change(term(),
                  #state{statuses :: #{binary() => serving_status()},
                         watchers :: #{binary() => #{pid() => reference()}},
                         monitors :: #{reference() => {binary(), pid()}}},
                  term()) ->
                     {ok,
                      #state{statuses :: #{binary() => serving_status()},
                             watchers :: #{binary() => #{pid() => reference()}},
                             monitors :: #{reference() => {binary(), pid()}}}}.

handle_call/3

-spec handle_call(term(),
                  {pid(), term()},
                  #state{statuses :: #{binary() => serving_status()},
                         watchers :: #{binary() => #{pid() => reference()}},
                         monitors :: #{reference() => {binary(), pid()}}}) ->
                     {reply,
                      term(),
                      #state{statuses :: #{binary() => serving_status()},
                             watchers :: #{binary() => #{pid() => reference()}},
                             monitors :: #{reference() => {binary(), pid()}}}}.

handle_cast(Msg, State)

-spec handle_cast(term(),
                  #state{statuses :: #{binary() => serving_status()},
                         watchers :: #{binary() => #{pid() => reference()}},
                         monitors :: #{reference() => {binary(), pid()}}}) ->
                     {noreply,
                      #state{statuses :: #{binary() => serving_status()},
                             watchers :: #{binary() => #{pid() => reference()}},
                             monitors :: #{reference() => {binary(), pid()}}}}.

handle_info/2

-spec handle_info(term(),
                  #state{statuses :: #{binary() => serving_status()},
                         watchers :: #{binary() => #{pid() => reference()}},
                         monitors :: #{reference() => {binary(), pid()}}}) ->
                     {noreply,
                      #state{statuses :: #{binary() => serving_status()},
                             watchers :: #{binary() => #{pid() => reference()}},
                             monitors :: #{reference() => {binary(), pid()}}}}.

init/1

-spec init([]) ->
              {ok,
               #state{statuses :: #{binary() => serving_status()},
                      watchers :: #{binary() => #{pid() => reference()}},
                      monitors :: #{reference() => {binary(), pid()}}}}.

set(Service, Status)

-spec set(binary(), serving_status()) -> ok.

Set a service's serving status and notify its watchers.

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

status(Service)

-spec status(binary()) -> {ok, serving_status()} | not_found.

The current status for Check: {ok, Status}, or not_found for a named service that was never registered (the overall server defaults to SERVING).

subscribe(Service)

-spec subscribe(binary()) -> serving_status().

Register the caller as a watcher of Service and return the current status to emit first. A named unknown service resolves to SERVICE_UNKNOWN (Watch keeps the stream open rather than erroring).

terminate(Reason, State)

-spec terminate(term(),
                #state{statuses :: #{binary() => serving_status()},
                       watchers :: #{binary() => #{pid() => reference()}},
                       monitors :: #{reference() => {binary(), pid()}}}) ->
                   ok.