# `Countersign.Workers.Delivery`
[🔗](https://github.com/mkreyman/countersign/blob/v0.1.0/lib/countersign/workers/delivery.ex#L1)

The Oban worker that delivers a request's link: the first send, a resend
and the reminder.

    defmodule MyApp.Signing.DeliveryWorker do
      use Countersign.Workers.Delivery, queue: :notifications, max_attempts: 5

      @impl Countersign.Workers.Delivery
      def config, do: MyApp.Signing.config()
    end

`job/2` builds the job for a request (`reminder: true` for the reminder).
Its args carry the request id, its scope and its `send_count`, never the
token or the address: the link is rebuilt from the row's encrypted token
when the job runs, so a resend's job delivers the newest link. A job is
unique on the request, its `send_count` and whether it is the reminder.

When the job runs:

  * a request that is gone, no longer pending, past its `expires_at`, or
    resent since the job was written (its `send_count` moved on) sends
    nothing and
    completes;
  * while `c:Countersign.Host.enabled?/1` answers false for the request's
    scope, it sends nothing and snoozes an hour, so neither a first
    delivery, a reminder nor a retry goes out while signing is switched
    off; the request stays pending, and expiry still ends it on its date;
  * `{:error, :retry}` from the delivery retries, and on the last attempt
    fails the request (`Countersign.Requests.fail/3`, reason
    `:max_attempts`) and cancels;
  * `{:error, {:permanent, reason}}` has already failed the request
    (`Countersign.Requests.deliver_link/3`) and cancels.

# `config`

```elixir
@callback config() :: Countersign.Config.t()
```

The config the worker delivers with.

# `args`

```elixir
@spec args(Countersign.Request.t(), keyword()) :: map()
```

A delivery job's args for `request` (`reminder: true` for the reminder).

# `perform`

```elixir
@spec perform(Countersign.Config.t(), Oban.Job.t()) ::
  :ok | {:error, :retry} | {:snooze, pos_integer()} | {:cancel, term()}
```

Runs a delivery job with `config` (what the generated `perform/1` calls).

---

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