Dsxir.OptimizerSession.Store behaviour (dsxir v0.3.0)

Copy Markdown

Behaviour for OptimizerSession checkpoint persistence.

Two reference implementations ship in dsxir:

Consumers wire their own Postgres / S3 / etc by implementing the four callbacks.

Summary

Functions

Resolve a store: option shortcut into a {module, opts} tuple.

Types

filter()

@type filter() :: keyword()

listing()

@type listing() :: %{
  session_id: session_id(),
  status: atom(),
  updated_at: DateTime.t(),
  optimizer: module(),
  best_score: float() | nil
}

opts()

@type opts() :: keyword()

session_id()

@type session_id() :: String.t()

store_spec()

@type store_spec() :: :ets | :file | {module(), keyword()}

Callbacks

delete_checkpoint(opts, session_id)

@callback delete_checkpoint(opts(), session_id()) :: :ok | {:error, term()}

get_checkpoint(opts, session_id)

@callback get_checkpoint(opts(), session_id()) ::
  {:ok, Dsxir.OptimizerSession.Checkpoint.t()} | {:error, :not_found | term()}

list_sessions(opts, filter)

@callback list_sessions(opts(), filter()) :: {:ok, [listing()]} | {:error, term()}

put_checkpoint(opts, session_id, t)

@callback put_checkpoint(opts(), session_id(), Dsxir.OptimizerSession.Checkpoint.t()) ::
  :ok | {:error, term()}

Functions

resolve(arg1)

@spec resolve(:ets | :file | {module(), keyword()} | nil) :: {module(), keyword()}

Resolve a store: option shortcut into a {module, opts} tuple.

Accepts:

  • :ets -> {Dsxir.OptimizerSession.Store.ETS, []}
  • :file -> {Dsxir.OptimizerSession.Store.File, dir: "priv/dsxir/sessions", format: :binary}
  • {module, opts} -> passed through.

Honors Application.get_env(:dsxir, :default_session_store, ...) for default override. The compile-time default is configured via config :dsxir, :default_session_store, ... (defaults to :file outside of test).