Countersign.Workers.Certificate behaviour (Countersign v0.1.0)

Copy Markdown View Source

The Oban worker that renders and stores one signed request's certificate (Countersign.Certificate). A host uses it and names it as the config's :certificate_worker; Countersign.Requests.sign/3 then inserts the job in the sign transaction.

defmodule MyApp.Signing.CertificateWorker do
  use Countersign.Workers.Certificate,
    queue: :exports,
    max_attempts: 10,
    time_zone: "America/Denver"

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

The job's args are the request's id and its scope; the request is loaded in that scope, so a job naming another scope finds nothing and cancels. One job per request (unique on the request id).

When the job runs:

  • a request not found in the job's scope, or not signed, cancels;
  • a request whose certificate_ref is set stores nothing and completes;
  • the certificate is rendered (Countersign.Certificate.render/3) outside any transaction, then, with the request row locked FOR UPDATE, checked for a certificate_ref again, stored through Countersign.Signable.store_document/4 and pinned; a rerun after a crash finds it pinned and stores nothing;
  • {:error, :busy} or {:error, :timeout} from rendering or storing snoozes the job 30 seconds, {:cancel, reason} from storing cancels it, and any other error retries it.

Options

  • :queue - default :default.
  • :max_attempts - default 10.
  • :time_zone - passed to Countersign.Certificate (default UTC only).

Summary

Callbacks

The config the worker renders and stores with.

Functions

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

Runs a certificate job (see the moduledoc).

Callbacks

config()

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

The config the worker renders and stores with.

Functions

args(request)

@spec args(Countersign.Request.t()) :: map()

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

perform(config, job, opts)

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

Runs a certificate job (see the moduledoc).