DDD.Outbox.DeadLetterHandler (vicander v0.1.1)

Copy Markdown View Source

A supervised process that applies a DDD.Outbox.DeadLetterPolicy to dead-lettered events.

The database is the source of truth. The poller sends this process a best-effort notify/0 when it gives up on an event, but a message can be lost if the process is down. So the process also sweeps for unresolved dead letters when it (re)starts and then periodically. If it crashes and restarts, nothing is lost: unresolved dead letters are simply found again.

Dead letters are claimed with a lease and FOR UPDATE SKIP LOCKED, so with several nodes each dead letter is handled once.

Options

  • :repo - (required) your Ecto.Repo
  • :policy - a DDD.Outbox.DeadLetterPolicy module (default DDD.Outbox.DeadLetterPolicy.Default, which keeps everything)
  • :sweep_interval_ms - how often to sweep (default 60_000)
  • :batch_size - dead letters per sweep (default 50)
  • :lease_ms - how long a claimed dead letter is reserved (default 30_000)

Each can also be set under config :vicander, :dead_letters; an option passed here wins.

Summary

Functions

Returns a specification to start this module under a supervisor.

Ask the handler to sweep now. A no-op when the process is not running.

Sweep now and return how many dead letters were handled (useful in tests).

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

notify()

Ask the handler to sweep now. A no-op when the process is not running.

start_link(opts)

sweep_now()

Sweep now and return how many dead letters were handled (useful in tests).