Outbox.Dispatcher (Outbox v0.1.0-beta.1)

Copy Markdown View Source

Polls the outbox_events table for undispatched events and fans them out to subscribers.

Invoked from Outbox.Ticker every ~5s via Task.Supervisor.start_child/2. Each invocation:

  1. Opens a transaction
  2. Selects up to @batch_size undispatched events ordered by id with FOR UPDATE SKIP LOCKED (multi-node safe; concurrent invocations on the same node are also safe)
  3. For each event, looks up subscribers via Outbox.Registry.lookup/1 and enqueues one Outbox.SubscriberJob per subscriber into the Outbox.Config.oban/0 instance
  4. Marks all processed events dispatched_at = utc_now()

An event with no registered subscribers is still marked dispatched (and a debug log is emitted). This prevents re-scanning on every tick.

Failures don't auto-retry — the next tick (5s later) is the retry. This is appropriate for a "drain the outbox" loop with no per-tick state to recover.

Summary

Functions

Run one dispatch pass: claim a batch of undispatched events, fan out to subscribers, mark dispatched. Returns :ok.

Functions

run()

@spec run() :: :ok

Run one dispatch pass: claim a batch of undispatched events, fan out to subscribers, mark dispatched. Returns :ok.