Skip to content

Commit

Permalink
feat: MIN_REQUESTS_PER_SECOND env var
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Dec 21, 2024
1 parent a480da5 commit ec2d1e7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions dank_mids/helpers/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,16 @@ async def handle_too_many_requests(self, endpoint: str, error: ClientResponseErr
if (now := time()) > getattr(limiter, "_last_updated_at", 0) + 10:
current_rate = limiter._rate_per_sec
new_rate = current_rate * 0.97
limiter.time_period /= 0.97
limiter._rate_per_sec = new_rate
limiter._last_updated_at = now
_logger_info(
"reduced requests per second for %s from %s to %s",
endpoint,
current_rate,
new_rate,
)
if new_rate >= ENVS.MIN_REQUESTS_PER_SECOND:
limiter.time_period /= 0.97
limiter._rate_per_sec = new_rate
limiter._last_updated_at = now
_logger_info(
"reduced requests per second for %s from %s to %s",
endpoint,
current_rate,
new_rate,
)

now = time()
self._last_rate_limited_at = now
Expand Down

0 comments on commit ec2d1e7

Please sign in to comment.