locus_loader (locus v2.3.15)

Copy Markdown View Source

Loads and unpacks databases while managing any associated assets (e.g. reading from and writing to cache).

Summary

Types

blob_format()

-type blob_format() :: tgz | tarball | gzip | gzipped_mmdb | mmdb | unknown.

error_retry_behaviour()

-type error_retry_behaviour() ::
          {backoff, milliseconds_interval()} | {exponential_backoff, exponential_backoff_params()}.

event()

event_cache_attempt_finished()

-type event_cache_attempt_finished() ::
          {cache_attempt_finished, locus_filesystem_store:path(), ok} |
          {cache_attempt_finished, locus_filesystem_store:path(), {error, term()}}.

exponential_backoff_params()

-type exponential_backoff_params() ::
          #{min_interval := milliseconds_interval(),
            max_interval := milliseconds_interval(),
            growth_base := milliseconds_interval(),
            growth_exponent := number()}.

fetcher_opt()

-type fetcher_opt() :: locus_maxmind_download:opt() | locus_http_download:opt().

loader_opt()

-type loader_opt() ::
          {update_period, milliseconds_interval()} |
          {error_retries, error_retry_behaviour()} |
          no_cache |
          {database_cache_file, file:filename_all()}.

maxmind_origin_params()

-type maxmind_origin_params() :: #{license_key := unicode:unicode_binary(), date => calendar:date()}.

milliseconds_interval()

-type milliseconds_interval() :: pos_integer().

msg()

-type msg() ::
          {event, event()} |
          {load_success, source(), calendar:datetime(), locus_mmdb:database()} |
          {load_failure, source(), Reason :: term()}.

opt()

-type opt() :: loader_opt() | fetcher_opt().

origin()

-type origin() ::
          {maxmind, atom()} |
          {http, locus_http_download:url()} |
          {filesystem, locus_filesystem_load:path()} |
          locus:custom_fetcher().

provider_source()

-type provider_source() :: {maxmind, atom()}.

source()

state()

-opaque state()

uniformly_distributed_update_period()

-type uniformly_distributed_update_period() :: #{min := pos_integer(), max := pos_integer()}.

update_period()

-type update_period() :: pos_integer() | uniformly_distributed_update_period().

Functions

code_change/3

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

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_info/2

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

init/1

-spec init([pid() | atom() | origin() | [loader_opt()] | [fetcher_opt()], ...]) -> {ok, state()}.

start_link(DatabaseId, Origin, LoaderOpts, FetcherOpts)

-spec start_link(atom(), origin(), [loader_opt()], [fetcher_opt()]) -> {ok, pid()}.

terminate(Reason, State)

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

valid_blob_formats()

-spec valid_blob_formats() -> [tgz | tarball | gzip | gzipped_mmdb | mmdb | unknown, ...].

validate_opts(Origin, MixedOpts)

-spec validate_opts(origin(), proplists:proplist()) ->
                       {ok, {[opt()], [fetcher_opt()], proplists:proplist()}} |
                       {error, BadOpt :: term()}.