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

Copy Markdown View Source

The Oban worker that runs the daily sweep (Countersign.Sweep): expiry, then one reminder for each request due one.

defmodule MyApp.Signing.DailyWorker do
  use Countersign.Workers.Daily, delivery: MyApp.Signing.DeliveryWorker

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

Schedule it with Oban's cron plugin. A job is unique for 23 hours, so a second insert the same day is dropped. The sweep's clock is the job's "now" arg (ISO 8601) when it has one, else Countersign.Host.now/0.

A reminder is a delivery job built by the :delivery worker's job/2 with reminder: true, inserted in the same transaction that marks the request reminded (:oban, the Oban instance, default Oban). Override enqueue_reminder/1 to enqueue it another way.

Summary

Callbacks

The config the sweep runs with.

Enqueues the reminder delivery for a request just marked reminded; answers :ok.

Functions

Runs the sweep with config: expiry first, so a reminder whose enqueue fails can never hold back a link's end, then reminders through enqueue. Answers how many requests it reminded and expired.

Callbacks

config()

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

The config the sweep runs with.

enqueue_reminder(t)

@callback enqueue_reminder(Countersign.Request.t()) :: :ok

Enqueues the reminder delivery for a request just marked reminded; answers :ok.

Functions

run(config, enqueue, args \\ %{})

@spec run(Countersign.Config.t(), (Countersign.Request.t() -> :ok), map()) ::
  {:ok, %{reminded: non_neg_integer(), expired: non_neg_integer()}}

Runs the sweep with config: expiry first, so a reminder whose enqueue fails can never hold back a link's end, then reminders through enqueue. Answers how many requests it reminded and expired.