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

The Oban worker that delivers one signing code. A host `use`s it and names
it as the config's `:code_worker`; `Countersign.Requests.request_code/2`
then inserts the job in the transaction that wrote the code.

    defmodule MyApp.Signing.CodeWorker do
      use Countersign.Workers.Code, queue: :notifications, max_attempts: 3

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

The job's args are the code's id, the request's id and its scope, never the
code: the worker decrypts it from `code_ciphertext` when it runs
(`Countersign.Requests.deliver_code/3`). One job per code.

When the job runs:

  * a code already used or past its 10 minutes, or a request the signer
    may no longer open, sends nothing and completes;
  * `{:error, :retry}` from the delivery retries, and on the last attempt
    gives up without failing the request: the signer can ask for a new
    code;
  * a permanent failure cancels the job, and has already failed a pending
    request (`Countersign.Requests.fail/3`).

# `config`

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

The config the worker delivers with.

# `args`

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

A code job's args: the code, its request and the request's scope.

# `perform`

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

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

---

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