MPP.Subscription.Store behaviour (mpp v0.16.0)

Copy Markdown View Source

Behaviour and dispatch helpers for method-neutral recurring-subscription persistence.

Updates must be atomic so concurrent renewal attempts cannot charge the same billing period twice. MPP.Subscription.ETSStore is the single-node default.

Summary

Functions

Return the application-started subscription store.

Delete a subscription through a store reference.

Look up a subscription through a store reference.

Persist a subscription through a store reference.

Atomically update a subscription through a store reference.

Types

store_ref()

@type store_ref() :: module() | {module(), keyword()}

update_fun()

@type update_fun() :: (MPP.Subscription.Record.t() | :not_found ->
                   {:ok, MPP.Subscription.Record.t()} | {:error, term()})

Callbacks

delete(t)

@callback delete(String.t()) :: :ok | {:error, term()}

get(t)

@callback get(String.t()) ::
  {:ok, MPP.Subscription.Record.t()} | :not_found | {:error, term()}

put(t)

@callback put(MPP.Subscription.Record.t()) :: :ok | {:error, term()}

update(t, update_fun)

@callback update(String.t(), update_fun()) ::
  {:ok, MPP.Subscription.Record.t()} | {:error, term()}

Functions

default_store()

@spec default_store() :: module()

Return the application-started subscription store.

delete(store, id)

@spec delete(store_ref(), String.t()) :: :ok | {:error, term()}

Delete a subscription through a store reference.

get(store, id)

@spec get(store_ref(), String.t()) ::
  {:ok, MPP.Subscription.Record.t()} | :not_found | {:error, term()}

Look up a subscription through a store reference.

put(store, record)

@spec put(store_ref(), MPP.Subscription.Record.t()) :: :ok | {:error, term()}

Persist a subscription through a store reference.

update(store, id, fun)

@spec update(store_ref(), String.t(), update_fun()) ::
  {:ok, MPP.Subscription.Record.t()} | {:error, term()}

Atomically update a subscription through a store reference.