diff --git a/backend/onyx/connectors/zendesk/connector.py b/backend/onyx/connectors/zendesk/connector.py index 05ab97986..17df88e76 100644 --- a/backend/onyx/connectors/zendesk/connector.py +++ b/backend/onyx/connectors/zendesk/connector.py @@ -40,6 +40,13 @@ class ZendeskClient: response = requests.get( f"{self.base_url}/{endpoint}", auth=self.auth, params=params ) + + if response.status_code == 429: + retry_after = response.headers.get("Retry-After") + if retry_after is not None: + # Sleep for the duration indicated by the Retry-After header + time.sleep(int(retry_after)) + response.raise_for_status() return response.json() diff --git a/backend/onyx/seeding/load_docs.py b/backend/onyx/seeding/load_docs.py index 980addf86..b629b6ac3 100644 --- a/backend/onyx/seeding/load_docs.py +++ b/backend/onyx/seeding/load_docs.py @@ -216,7 +216,7 @@ def seed_initial_documents( # Retries here because the index may take a few seconds to become ready # as we just sent over the Vespa schema and there is a slight delay - index_with_retries = retry_builder()(document_index.index) + index_with_retries = retry_builder(tries=15)(document_index.index) index_with_retries(chunks=chunks, fresh_index=cohere_enabled) # Mock a run for the UI even though it did not actually call out to anything diff --git a/backend/onyx/utils/retry_wrapper.py b/backend/onyx/utils/retry_wrapper.py index 1d62e7dc5..ef7107099 100644 --- a/backend/onyx/utils/retry_wrapper.py +++ b/backend/onyx/utils/retry_wrapper.py @@ -15,11 +15,12 @@ F = TypeVar("F", bound=Callable[..., Any]) def retry_builder( - tries: int = 10, + tries: int = 20, delay: float = 0.1, - max_delay: float | None = None, + max_delay: float | None = 60, backoff: float = 2, jitter: tuple[float, float] | float = 1, + exceptions: type[Exception] | tuple[type[Exception], ...] = (Exception,), ) -> Callable[[F], F]: """Builds a generic wrapper/decorator for calls to external APIs that may fail due to rate limiting, flakes, or other reasons. Applies exponential @@ -33,6 +34,7 @@ def retry_builder( backoff=backoff, jitter=jitter, logger=cast(Logger, logger), + exceptions=exceptions, ) def wrapped_func(*args: list, **kwargs: dict[str, Any]) -> Any: return func(*args, **kwargs)