Skip to content

Commit

Permalink
fix: (HttpClient) rate limit fix unlimited tries (#171)
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Inzhyyants <[email protected]>
  • Loading branch information
artem1205 authored Dec 18, 2024
1 parent adef1e8 commit 4759654
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions airbyte_cdk/sources/streams/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _send_with_retry(
user_backoff_handler = user_defined_backoff_handler(max_tries=max_tries, max_time=max_time)(
self._send
)
rate_limit_backoff_handler = rate_limit_default_backoff_handler()
rate_limit_backoff_handler = rate_limit_default_backoff_handler(max_tries=max_tries)
backoff_handler = http_client_default_backoff_handler(
max_tries=max_tries, max_time=max_time
)
Expand Down Expand Up @@ -472,7 +472,9 @@ def _handle_error_resolution(

elif retry_endlessly:
raise RateLimitBackoffException(
request=request, response=response or exc, error_message=error_message
request=request,
response=(response if response is not None else exc),
error_message=error_message,
)

raise DefaultBackoffException(
Expand Down
7 changes: 5 additions & 2 deletions unit_tests/sources/streams/http/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
from airbyte_cdk.sources.streams.http.exceptions import (
DefaultBackoffException,
RateLimitBackoffException,
RequestBodyException,
UserDefinedBackoffException,
)
Expand Down Expand Up @@ -690,10 +691,12 @@ def backoff_time(self, *args, **kwargs):

@pytest.mark.parametrize(
"exit_on_rate_limit, expected_call_count, expected_error",
[[True, 6, DefaultBackoffException], [False, 38, OverflowError]],
[[True, 6, DefaultBackoffException], [False, 6, RateLimitBackoffException]],
)
@pytest.mark.usefixtures("mock_sleep")
def test_backoff_strategy_endless(exit_on_rate_limit, expected_call_count, expected_error):
def test_backoff_strategy_endless(
exit_on_rate_limit: bool, expected_call_count: int, expected_error: Exception
):
http_client = HttpClient(
name="test", logger=MagicMock(), error_handler=HttpStatusErrorHandler(logger=MagicMock())
)
Expand Down

0 comments on commit 4759654

Please sign in to comment.