From 8d60cd160d67ec032c715cd22f203d19ac3c1d35 Mon Sep 17 00:00:00 2001 From: xacadil <92389481+xacadil@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:26:54 -0600 Subject: [PATCH] Backoff revision. (#25) --- tap_restaurant365/client.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tap_restaurant365/client.py b/tap_restaurant365/client.py index ad8533f..2fa06d4 100644 --- a/tap_restaurant365/client.py +++ b/tap_restaurant365/client.py @@ -4,9 +4,10 @@ from datetime import timedelta from http import HTTPStatus -from typing import Any, Callable, Optional +from typing import Any, Callable, Generator from urllib.parse import parse_qs, urlparse +import backoff import requests from dateutil import parser from singer_sdk.authenticators import BasicAuthenticator @@ -115,3 +116,24 @@ def validate_response(self, response: requests.Response) -> None: ): msg = self.response_error_message(response) raise FatalAPIError(msg) + + def backoff_wait_generator(self) -> Generator[float, None, None]: + """The wait generator used by the backoff decorator on request failure. + + See for options: + https://github.com/litl/backoff/blob/master/backoff/_wait_gen.py + + And see for examples: `Code Samples <../code_samples.html#custom-backoff>`_ + + Returns: + The wait generator + """ + return backoff.expo(factor=5) + + def backoff_max_tries(self) -> int: + """The number of attempts before giving up when retrying requests. + + Returns: + Number of max retries. + """ + return 8