Chimeway.Dispatch behaviour (chimeway v1.2.0)

Copy Markdown View Source

Behaviour contract for the dispatcher seam.

Configure the dispatcher via:

config :chimeway, :dispatcher, Chimeway.Dispatch.Sync

The default implementation is Chimeway.Dispatch.Sync, which plans and executes deliveries in the calling process. Configure Chimeway.Dispatch.Oban to plan deliveries and enqueue their adapter calls as background jobs.

Dispatch is called after notification creation, outside the notification Ecto.Multi transaction. Adapter calls must never hold a DB transaction open.

Summary

Callbacks

dispatch(notifications, opts)

@callback dispatch(
  notifications :: [Chimeway.Notifications.Notification.t()],
  opts :: keyword()
) ::
  {:ok, [Chimeway.Delivery.t()]} | {:error, term()}

dispatch_delivery(delivery_or_id, opts)

@callback dispatch_delivery(
  delivery_or_id :: Chimeway.Delivery.t() | binary(),
  opts :: keyword()
) ::
  {:ok, Chimeway.Delivery.t()}
  | {:skip, Chimeway.Delivery.t()}
  | {:error, term()}