# `Mailglass.Outbound.Worker`
[🔗](https://github.com/szTheory/mailglass/blob/v1.0.0/lib/mailglass/outbound/worker.ex#L2)

Oban worker that dispatches a queued Delivery (SEND-03). Conditionally
compiled — entire module elided when `:oban` is not loaded.

## Args schema (api_stability.md §Outbound.Worker)

    %{
      "delivery_id" => binary(),          # UUIDv7 string
      "mailglass_tenant_id" => binary()   # matches Mailglass.Oban.TenancyMiddleware contract
    }

**Never** serialize `%Message{}` into args — adopter types may not
be JSON-safe (functions, PIDs, structs with private fields).

## Options locked (api_stability.md §Outbound.Worker)

- `queue: :mailglass_outbound`
- `max_attempts: 20` — transactional SLAs are tight; exponential
  backoff reaches ~hours by attempt 20
- `unique: [period: 3600, fields: [:args], keys: [:delivery_id]]` —
  prevents double-enqueue on retry storms

## perform/1 flow

1. `TenancyMiddleware.wrap_perform/2` restores `Mailglass.Tenancy.current/0`
   from args
2. `Mailglass.Outbound.dispatch_by_id/1` hydrates the Delivery by id,
   calls the adapter OUTSIDE the job's transaction, writes Multi#2

---

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