Statsig.DataStore behaviour (statsig_elixir v0.16.3)

Behaviour and helper APIs for implementing a custom Statsig data store in Elixir.

A data store implementation is a module that implements the callbacks in this behaviour. Use start_link/3 to launch the bridge process and pass the returned %Statsig.DataStore.Reference{} into Statsig.Options.

Summary

Types

Opaque state returned from user callbacks.

Functions

Starts a bridge process for the provided implementation module.

Stops the bridge process for the given reference.

Types

state()

@type state() :: term()

Opaque state returned from user callbacks.

Callbacks

handle_get(t, state)

@callback handle_get(String.t(), state()) ::
  {:ok, %Statsig.DataStore.Response{result: term(), time: term()}, state()}
  | {:error, term()}

handle_initialize(state)

(optional)
@callback handle_initialize(state()) :: {:ok, state()} | {:error, term()}

handle_set(t, t, arg3, state)

(optional)
@callback handle_set(String.t(), String.t(), non_neg_integer() | nil, state()) ::
  {:ok, state()} | {:error, term()}

handle_shutdown(state)

(optional)
@callback handle_shutdown(state()) :: {:ok, state()} | {:error, term()}

handle_support_polling_updates_for(t, state)

(optional)
@callback handle_support_polling_updates_for(String.t(), state()) ::
  {:ok, boolean(), state()} | {:error, term()}

init(init_arg)

@callback init(init_arg :: term()) :: {:ok, state()} | {:error, term()}

Functions

start_link(module, init_arg \\ nil, opts \\ [])

@spec start_link(module(), term(), Keyword.t()) ::
  {:ok, Statsig.DataStore.Reference.t()} | {:error, term()}

Starts a bridge process for the provided implementation module.

Returns {:ok, %Statsig.DataStore.Reference{}} which can be assigned to %Statsig.Options{data_store: reference}.

stop(reference, reason \\ :normal, timeout \\ 5000)

@spec stop(Statsig.DataStore.Reference.t(), term(), non_neg_integer()) :: :ok

Stops the bridge process for the given reference.