File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
integrations/launch_darkly
tests/unit/integrations/launch_darkly Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -38,11 +38,19 @@ def _get_retry_after(exc: RequestException) -> float | None:
3838 (response := exc .response ) is not None
3939 ) and response .status_code == HTTP_429_TOO_MANY_REQUESTS :
4040 headers = response .headers
41+ # Clients must wait at least `Retry-After` seconds
42+ # before making additional calls to the API
4143 if retry_after := headers .get ("Retry-After" ):
4244 return float (retry_after )
45+ # The time at which the current rate limit window resets in epoch milliseconds
4346 if ratelimit_reset := headers .get ("X-Ratelimit-Reset" ):
44- return float (ratelimit_reset ) - timezone_now ().timestamp ()
45- # We have no retry information, use a default backoff time
47+ timestamp = int (ratelimit_reset ) / 1000
48+ # Use default backoff time if the timestamp is in the past.
49+ return (
50+ max (timestamp - timezone_now ().timestamp (), 0 )
51+ or BACKOFF_DEFAULT_RETRY_AFTER_SECONDS
52+ )
53+ # If no retry information retrieved, use a default backoff time
4654 # of 10 seconds as per LD documentation.
4755 return BACKOFF_DEFAULT_RETRY_AFTER_SECONDS
4856 return None
Original file line number Diff line number Diff line change @@ -214,7 +214,7 @@ def test_launch_darkly_client__get_flag_tags__return_expected(
214214
215215@pytest .mark .parametrize (
216216 "response_headers" ,
217- [{"Retry-After" : "0.1" }, {"X-Ratelimit-Reset" : "1672531200.1 " }],
217+ [{"Retry-After" : "0.1" }, {"X-Ratelimit-Reset" : "1672531200100 " }],
218218)
219219@pytest .mark .freeze_time ("2023-01-01T00:00:00Z" )
220220def test_launch_darkly_client__rate_limit__expected_backoff (
@@ -252,7 +252,7 @@ def test_launch_darkly_client__rate_limit__expected_backoff(
252252
253253@pytest .mark .parametrize (
254254 "response_headers" ,
255- [{"Retry-After" : "0.1" }, {"X-Ratelimit-Reset" : "1672531200.1 " }],
255+ [{"Retry-After" : "0.1" }, {"X-Ratelimit-Reset" : "1672531200100 " }],
256256)
257257@pytest .mark .freeze_time ("2023-01-01T00:00:00Z" )
258258def test_launch_darkly_client__rate_limit_max_retries__raises_expected (
You can’t perform that action at this time.
0 commit comments