Countersign.Sweep (Countersign v0.1.0)

Copy Markdown View Source

The daily sweep over pending requests (Countersign.Workers.Daily runs it): one reminder for each request sent long enough ago, then expiry for each request past its expires_at.

Both walk one scope at a time, in pages of 500 rows along signing_requests_due_index, and move each row with a conditional update that only matches a request that is still pending. A request signed, revoked or reminded meanwhile is left as it is, so two sweeps running at once never remind or expire one request twice.

Summary

Functions

Marks every pending request whose expires_at is at or before now expired, clears its token, and reports :expire to Countersign.Host.audit/3 and Countersign.Host.notify/2. Expiry runs whatever Countersign.Host.enabled?/1 answers: a link switched off must still stop working on its date. Answers how many expired.

Sends one reminder to every pending request whose reminded_at is nil and whose last_sent_at is at least Countersign.Host.reminder_days/1 days before now. A scope whose reminder days are 0, or whose Countersign.Host.enabled?/1 answers false, gets none, and its requests keep reminded_at nil so a later sweep reminds them once it is back on.

Functions

expire(config, now)

Marks every pending request whose expires_at is at or before now expired, clears its token, and reports :expire to Countersign.Host.audit/3 and Countersign.Host.notify/2. Expiry runs whatever Countersign.Host.enabled?/1 answers: a link switched off must still stop working on its date. Answers how many expired.

remind(config, now, enqueue)

Sends one reminder to every pending request whose reminded_at is nil and whose last_sent_at is at least Countersign.Host.reminder_days/1 days before now. A scope whose reminder days are 0, or whose Countersign.Host.enabled?/1 answers false, gets none, and its requests keep reminded_at nil so a later sweep reminds them once it is back on.

For each request reminded, reminded_at is set and enqueue is called with the request in the same transaction, so a reminder whose delivery job could not be written is not marked sent. enqueue answers :ok; anything else rolls the row back and raises. Answers how many were reminded.