RateLimitPolicy

RateLimitPolicy#

class rapidtools.processing.RateLimitPolicy(cooldown_seconds: float = 30.0, max_asset_retries: int = 2)[source]#

Bases: object

Shared back-off applied by AssetAnalyzer to hosted APIs.

When a request fails (rate limit, transient error, safety block), every worker pauses for cooldown_seconds multiplied by the number of consecutive failures; the first success resets the multiplier.

Assets whose request failed are retried in additional passes once the first pass is complete (max_asset_retries), so a burst of 429s or timeouts does not leave holes in the results.

Variables:
  • cooldown_seconds (float) – Base pause after a failure. 0 disables pausing.

  • max_asset_retries (int) – Extra passes over the assets that failed. 0 disables retries.

Example

>>> RateLimitPolicy(cooldown_seconds=10).wait_for(3)
30
>>> RateLimitPolicy(max_asset_retries=1).max_asset_retries
1

Methods

wait_for

Return the pause (seconds) after consecutive_errors failures.

wait_for(consecutive_errors: int) → float[source]#

Return the pause (seconds) after consecutive_errors failures.