datetime/rate_limit_schedule_utils library
Rate-limiting schedule shaper: max N per rolling period plus a cooldown — roadmap #612.
Given a stream of requested event times, this computes the actual times at which the events may fire under two constraints applied together:
- Cooldown: at least
cooldownmust elapse between consecutive fires. - Window quota: no more than
maxPerPeriodfires within any rolling window of lengthperiod.
Events are never dropped — one that would breach a limit is pushed later to the earliest instant that satisfies both rules. This models notification throttling, API call pacing, and "max 3 emails per day, 1 hour apart" style policies that apps otherwise hand-roll with brittle timestamp math.
Requested times must be supplied in non-decreasing order; the shaper processes them as a queue and assumes monotonic input.
Classes
- RateLimitSchedule
- Computes rate-limited fire times from requested times.