locus_custom_fetcher behaviour (locus v2.3.14)

View Source

Callbacks for providing your own database fetcher

Summary

Types

description/0

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

event/0

event_load_attempt_dismissed/0

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

event_load_attempt_started/0

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

msg/0

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

source/0

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

state/0

-opaque state()

success/0

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

successful_fetch_metadata/0

-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/1

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

fetch/1

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