March Docs

Conduit.RateLimiter

Functions

fnacquireacquire(storage, job_type : String, config : Conduit.RateLimit, payload : String) : Result(Bool, String)#

Attempt to acquire a rate-limit token for the given job.

Returns:
  Ok(true)  — token acquired, job may proceed
  Ok(false) — rate-limited, job should be snoozed
  Err(e)    — storage error (treat as allowed to avoid blocking the queue)

When Ok(false) is returned, call `snooze_duration/1` to compute how long
to wait before retrying.

The backend in `config` controls how tokens are tracked:
- `StorageBacked`: Postgres token bucket via the storage interface (default)
- `Custom(f)`: user-supplied function, e.g. for Redis or in-process buckets
fnsnooze_durationsnooze_duration(rate : Int) : Int#

Compute how long to snooze a rate-limited job (in milliseconds).

For a rate of N tokens/second, the minimum wait is 1000/N ms.
We add a small jitter (0–100ms) to avoid thundering herd.