# `DDD.Outbox.DeadLetterHandler`
[🔗](https://github.com/blackuprise/vicander/blob/v0.1.1/lib/ddd/events/outbox/dead_letter_handler.ex#L1)

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.

# `child_spec`

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`

# `sweep_now`

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
