pub struct SendCooldown { /* private fields */ }Expand description
A cooldown ledger over the Database port. Construct it with the table
the owning module declares (e.g. "<module>_send_cooldown"); the
owning module ships create_table_sql as a
migration.
Timestamps are RFC 3339 strings from the Clock port, the same shape
the house stores in TEXT columns everywhere: lexicographic order on
that format is chronological order, which is what the window compare
relies on.
Implementations§
Source§impl SendCooldown
impl SendCooldown
pub fn new(table: impl Into<String>) -> Self
Sourcepub fn create_table_sql(&self) -> String
pub fn create_table_sql(&self) -> String
The portable DDL for the cooldown table (renders identically on SQLite/D1 and Postgres, ADR 0004).
Sourcepub async fn try_acquire(
&self,
db: &dyn Database,
subject: &str,
now: &str,
cutoff: &str,
) -> Result<bool, DbError>
pub async fn try_acquire( &self, db: &dyn Database, subject: &str, now: &str, cutoff: &str, ) -> Result<bool, DbError>
Claims the send window for subject: true for the one caller
whose claim lands, false for anyone inside the window.
now is the RFC 3339 timestamp to record, cutoff the instant
(now - window) after which an expired claim may be renewed. The
update-then-insert pair is race-free: the guarded UPDATE can be
won by exactly one writer, and the conflict-insert covers the row
not existing (yet).
§Errors
Returns DbError if either write fails.
Trait Implementations§
Source§impl Clone for SendCooldown
impl Clone for SendCooldown
Source§fn clone(&self) -> SendCooldown
fn clone(&self) -> SendCooldown
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more