AshDispatch.Transports.Oban (AshDispatch v0.5.1)

View Source

Oban-job-enqueue transport.

Eliminates the "two-channel dance" where a producer dispatches an AshDispatch event for observability AND separately calls MyWorker.new(args) |> Oban.insert/1 for the side-effect work. With this transport, the producer dispatches once; the event declaration carries the worker + unique-keys in :metadata, and the dispatcher enqueues the worker as one of the event's channels.

Channel config

[transport: :oban, audience: :system]

Event metadata

event :my_event,
  channels: [
    [transport: :broadcast, audience: :admin],
    [transport: :oban,      audience: :system]
  ],
  metadata: [
    oban_worker: MyApp.Workers.DoTheThing,
    # Optional. When present, passed to `MyApp.Workers.DoTheThing.new/2`
    # as `unique: [keys: <oban_unique_keys>]`. Use to dedupe enqueues
    # on a subset of args (e.g. `[:entry_id]`).
    oban_unique_keys: [:entry_id]
  ]

The job args are context.data (the third argument to Dispatcher.dispatch/3) with string keys (Oban requires JSON-serializable args; the dispatcher stringifies atom keys here so producers can keep idiomatic atom keys in their dispatch payloads).

Lightweight (no receipt)

Like :broadcast, this transport is lightweight — no DeliveryReceipt row is created (the enqueued oban_jobs row IS the audit trail). Producers who want a receipt should pair :oban with another transport on the same event.

Failure semantics

  • Missing oban_worker in metadata → logs a warning, returns {:ok, receipt} with skipped: "missing_oban_worker". The other channels still deliver. Treats configuration drift as a soft-fail rather than crashing producers.
  • Oban.insert/1 returns {:error, _} → logs at :error, propagates as {:error, reason} (the dispatcher swallows per-channel errors so other channels keep delivering — matches the email/discord/slack precedent).
  • Oban unavailable / not started → caught by the rescue; returns {:error, exception} per the same precedent.

Status

Single consumer at ship time: Mosis (sibling repo). Extend as needed — same shape as the receipt-skip channels.

Summary

Functions

Enqueues the configured Oban worker with context.data as args.

Functions

deliver(receipt, context, channel, event_config)

Enqueues the configured Oban worker with context.data as args.

Parameters

  • receipt — pseudo-receipt (id: nil); not persisted for this transport
  • contextAshDispatch.Context.t with :event_id + :data
  • channelAshDispatch.Channel.t (transport + audience only used for telemetry / logs)
  • event_config — event registration keyword list including :metadata with :oban_worker and optional :oban_unique_keys