Skip to content
6 changes: 6 additions & 0 deletions meltano.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ plugins:
value: '2024-02-15'
- name: start_date
value: '2000-01-01'
- name: max_retries
value: 5
- name: backoff_factor
value: 2
- name: retry_statuses
value: [400]
loaders:
- name: target-jsonl
variant: andyh1203
Expand Down
19 changes: 19 additions & 0 deletions tap_klaviyo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from urllib.parse import parse_qsl

from singer_sdk.authenticators import APIKeyAuthenticator
from singer_sdk.exceptions import RetriableAPIError
from singer_sdk.pagination import BaseHATEOASPaginator
from singer_sdk.streams import RESTStream

Expand Down Expand Up @@ -76,6 +77,24 @@ def http_headers(self) -> dict:
headers["revision"] = self.config.get("revision")
return headers

def validate_response(self, response: requests.Response) -> None:
if not response.ok and response.status_code in self.config.get("retry_statuses", {}):
error_message = (
f"Retryable error {response.status_code} {response.reason} "
f"for URL {response.url}"
)
raise RetriableAPIError(error_message)
super().validate_response(response)

def backoff_max_tries(self) -> int:
return int(self.config.get("max_retries", 3))

def backoff_wait_generator(self) -> t.Generator[float, None, None]:
backoff_factor = float(self.config.get("backoff_factor", 2))
max_tries = self.backoff_max_tries()
for attempt in range(max_tries):
yield backoff_factor * (2**attempt)

def get_new_paginator(self) -> BaseHATEOASPaginator:
return KlaviyoPaginator()

Expand Down