Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backoff connection related errors. #4

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion tap_klaviyo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

import re
from datetime import datetime
from typing import Any, Dict, Optional
from typing import Any, Dict, Optional, Callable

import requests
from backports.cached_property import cached_property
from pendulum import parse
from singer_sdk import typing as th
from singer_sdk.authenticators import APIKeyAuthenticator
from singer_sdk.exceptions import FatalAPIError, RetriableAPIError
from singer_sdk.helpers.jsonpath import extract_jsonpath
from singer_sdk.streams import RESTStream

from tap_klaviyo.auth import KlaviyoAuthenticator
from urllib.parse import urlparse, parse_qs
from urllib3.exceptions import ProtocolError, InvalidChunkLength
from requests.exceptions import ReadTimeout, ChunkedEncodingError
import backoff


class KlaviyoStream(RESTStream):
Expand Down Expand Up @@ -211,3 +215,22 @@ def get_schema(self) -> dict:
@cached_property
def schema(self) -> dict:
return self.get_schema()

def request_decorator(self, func: Callable) -> Callable:
"""Instantiate a decorator for handling request failures."""
decorator: Callable = backoff.on_exception(
backoff.expo,
(
RetriableAPIError,
ReadTimeout,
ConnectionError,
ConnectionResetError,
ProtocolError,
InvalidChunkLength,
requests.RequestException,
ChunkedEncodingError,
),
max_tries=8,
factor=5,
)(func)
return decorator
Loading