airbyte_cdk.sources.streams.http.error_handlers.backoff_strategy
1# 2# Copyright (c) 2023 Airbyte, Inc., all rights reserved. 3# 4 5from abc import ABC, abstractmethod 6from typing import Optional, Union 7 8import requests 9 10 11class BackoffStrategy(ABC): 12 @abstractmethod 13 def backoff_time( 14 self, 15 response_or_exception: Optional[Union[requests.Response, requests.RequestException]], 16 attempt_count: int, 17 ) -> Optional[float]: 18 """ 19 Override this method to dynamically determine backoff time e.g: by reading the X-Retry-After header. 20 21 This method is called only if should_backoff() returns True for the input request. 22 23 :param response_or_exception: The response or exception that caused the backoff. 24 :param attempt_count: The number of attempts already performed for this request. 25 :return how long to backoff in seconds. The return value may be a floating point number for subsecond precision. Returning None defers backoff 26 to the default backoff behavior (e.g using an exponential algorithm). 27 """ 28 pass
class
BackoffStrategy(abc.ABC):
12class BackoffStrategy(ABC): 13 @abstractmethod 14 def backoff_time( 15 self, 16 response_or_exception: Optional[Union[requests.Response, requests.RequestException]], 17 attempt_count: int, 18 ) -> Optional[float]: 19 """ 20 Override this method to dynamically determine backoff time e.g: by reading the X-Retry-After header. 21 22 This method is called only if should_backoff() returns True for the input request. 23 24 :param response_or_exception: The response or exception that caused the backoff. 25 :param attempt_count: The number of attempts already performed for this request. 26 :return how long to backoff in seconds. The return value may be a floating point number for subsecond precision. Returning None defers backoff 27 to the default backoff behavior (e.g using an exponential algorithm). 28 """ 29 pass
Helper class that provides a standard way to create an ABC using inheritance.
@abstractmethod
def
backoff_time( self, response_or_exception: Union[requests.models.Response, requests.exceptions.RequestException, NoneType], attempt_count: int) -> Optional[float]:
13 @abstractmethod 14 def backoff_time( 15 self, 16 response_or_exception: Optional[Union[requests.Response, requests.RequestException]], 17 attempt_count: int, 18 ) -> Optional[float]: 19 """ 20 Override this method to dynamically determine backoff time e.g: by reading the X-Retry-After header. 21 22 This method is called only if should_backoff() returns True for the input request. 23 24 :param response_or_exception: The response or exception that caused the backoff. 25 :param attempt_count: The number of attempts already performed for this request. 26 :return how long to backoff in seconds. The return value may be a floating point number for subsecond precision. Returning None defers backoff 27 to the default backoff behavior (e.g using an exponential algorithm). 28 """ 29 pass
Override this method to dynamically determine backoff time e.g: by reading the X-Retry-After header.
This method is called only if should_backoff() returns True for the input request.
Parameters
- response_or_exception: The response or exception that caused the backoff.
- attempt_count: The number of attempts already performed for this request. :return how long to backoff in seconds. The return value may be a floating point number for subsecond precision. Returning None defers backoff to the default backoff behavior (e.g using an exponential algorithm).