locus_custom_fetcher behaviour (locus v2.3.15)

Copy Markdown View Source

Callbacks for providing your own database fetcher.

Summary

Types

description()

-type description() :: #{database_is_stored_remotely := boolean(), database_is_fetched_from := term()}.

event()

event_load_attempt_dismissed()

-type event_load_attempt_dismissed() :: {load_attempt_dismissed, source()}.

event_load_attempt_started()

-type event_load_attempt_started() :: {load_attempt_started, source()}.

msg()

-type msg() ::
          {event, event()} |
          {finished, {success, success()}} |
          {finished, dismissed} |
          {finished, {error, term()}}.

source()

-type source() :: {local | remote, {custom, term()}}.

state()

-opaque state()

success()

-type success() ::
          #{format := locus_loader:blob_format(),
            content := binary(),
            metadata := successful_fetch_metadata()}.

successful_fetch_metadata()

-type successful_fetch_metadata() ::
          #{fetched_from := term(), modified_on := calendar:datetime() | unknown}.

Callbacks

conditionally_fetch/2

-callback conditionally_fetch(Args, {depending_on, PreviousFetchMetadata}) ->
                                 {fetched, Success} | dismissed | {error, Reason}
                                 when
                                     Args :: term(),
                                     PreviousFetchMetadata :: successful_fetch_metadata(),
                                     Success :: success(),
                                     Reason :: term().

description(Args)

-callback description(Args) -> description() when Args :: term().

fetch(Args)

-callback fetch(Args) -> {fetched, Success} | {error, Reason}
                   when Args :: term(), Success :: success(), Reason :: term().

Functions

code_change/3

-spec code_change(term(), state(), term()) -> {ok, state()}.

description(Module, Args)

-spec description(module(), term()) -> description().

handle_call(Call, From, State)

-spec handle_call(term(), {pid(), reference()}, state()) -> {stop, unexpected_call, state()}.

handle_cast(Cast, State)

-spec handle_cast(term(), state()) -> {stop, unexpected_cast, state()}.

handle_continue/2

-spec handle_continue(fetch, state()) -> {stop, normal, state()}.

handle_info(Info, State)

-spec handle_info(term(), state()) -> {stop, unexpected_info, state()}.

init/1

-spec init([InitArg, ...]) -> {ok, state(), {continue, fetch}}
              when
                  InitArg :: OwnerPid | Source | Module | Args | PreviousFetchMetadata,
                  OwnerPid :: pid(),
                  Source :: source(),
                  Module :: module(),
                  Args :: term(),
                  PreviousFetchMetadata :: successful_fetch_metadata() | undefined.

source(Module, Args)

-spec source(module(), term()) -> source().

start_link(Source, Module, Args, PreviousFetchMetadata)

-spec start_link(source(), module(), term(), successful_fetch_metadata() | undefined) -> {ok, pid()}.

terminate(Reason, State)

-spec terminate(term(), state()) -> ok.