Skip to content

Commit

Permalink
fix: add logic to slow down api calls to avoid rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
am6010 committed Oct 3, 2024
1 parent 277d8bf commit 9cb8b4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-recurly/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from setuptools import find_packages, setup

MAIN_REQUIREMENTS = ["airbyte-cdk~=0.1", "recurly==4.10.0", "requests"]
MAIN_REQUIREMENTS = ["airbyte-cdk==0.67", "recurly==4.10.0", "requests"]

TEST_REQUIREMENTS = [
"pytest~=6.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

import re
import time
from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Union

from airbyte_cdk.models import SyncMode
Expand Down Expand Up @@ -128,11 +129,16 @@ def read_records(
if self.end_time:
params.update({END_TIME_PARAM: self.end_time})

items = getattr(self._client, self.client_method_name)(params=params).items()
pages = getattr(self._client, self.client_method_name)(params=params).pages()

# Call the Recurly client methods
for item in items:
yield self._item_to_dict(item)
for page in pages:
for item in page:
yield self._item_to_dict(item)
# slow down the API calls to avoid rate limiting
# https://recurly.com/developers/api-v2/v2.2/#section/Rate-Limits
# making 5 API calls per second / 300 API calls per minute / 1500 API calls per 5 minutes
time.sleep(0.2)

def get_updated_state(self, current_stream_state: MutableMapping[str, Any], latest_record: Mapping[str, Any]):
"""
Expand Down

0 comments on commit 9cb8b4a

Please sign in to comment.