quota
Rate limiting and usage quota enforcement per tenant. Tracks requests, tokens, and cost across time windows (minute, hour, day). Supports Postgres and Dragonfly backends with override rules and cleanup.
Used by cmd/worker, cmd/ui.
Usage
import "cruvero/internal/quota"
Key Types / Interfaces
| Type | Source | Description |
|---|---|---|
QuotaStore | store.go | Interface for quota tracking: increment, check, reset, override |
MaintenanceStore | store.go | Interface for quota data cleanup |
QuotaState | types.go | Current quota state for a tenant-window pair |
QuotaDecision | types.go | Decision: allowed, reason, retry-after, remaining |
QuotaRemaining | types.go | Remaining quota metrics (requests, tokens, cost) |
Limits | types.go | Quota limits per time window and cost cap |
OverrideRule | types.go | Temporary quota override with expiration |
QuotaExceededError | types.go | Custom error for quota exceeded |
TokenBucket | bucket.go | Token bucket rate limiter |
SlidingWindow | window.go | Sliding window quota limiter |