macula_discovery (macula v0.20.5)

View Source

Generic DHT-based service discovery. Provides cache-integrated lookup and announcement operations. Used by both pub/sub and RPC discovery layers.

Summary

Functions

Announce value to DHT.

Filter items by age based on last_seen timestamp and TTL. Items must have #{last_seen := integer()} in their structure.

Find values for a key via DHT lookup.

Find values with cache (default TTL: 300 seconds).

Find values with cache and custom TTL.

Remove value from DHT.

Types

key/0

-type key() :: binary().

lookup_fun/0

-type lookup_fun() :: fun((key()) -> {ok, [value()]} | {error, term()}).

publish_fun/0

-type publish_fun() :: fun((key()) -> ok | {error, term()}).

unpublish_fun/0

-type unpublish_fun() :: fun((key()) -> ok | {error, term()}).

value/0

-type value() :: term().

Functions

announce(Key, PublishFun)

-spec announce(key(), publish_fun()) -> ok | {error, term()}.

Announce value to DHT.

filter_by_age(Items, TTL, TimestampField)

-spec filter_by_age([map()], pos_integer(), atom()) -> [map()].

Filter items by age based on last_seen timestamp and TTL. Items must have #{last_seen := integer()} in their structure.

find(Key, LookupFun)

-spec find(key(), lookup_fun()) -> {ok, [value()]} | {error, term()}.

Find values for a key via DHT lookup.

find_with_cache(Key, Cache, LookupFun)

-spec find_with_cache(key(), macula_cache:cache(), lookup_fun()) ->
                         {ok, [value()], macula_cache:cache()} | {error, term(), macula_cache:cache()}.

Find values with cache (default TTL: 300 seconds).

find_with_cache(Key, Cache, LookupFun, TTL)

-spec find_with_cache(key(), macula_cache:cache(), lookup_fun(), pos_integer()) ->
                         {ok, [value()], macula_cache:cache()} | {error, term(), macula_cache:cache()}.

Find values with cache and custom TTL.

unannounce(Key, UnpublishFun)

-spec unannounce(key(), unpublish_fun()) -> ok | {error, term()}.

Remove value from DHT.