Skip to content

Commit

Permalink
Zendesk Retries (#3558)
Browse files Browse the repository at this point in the history
* k

* k

* k

* k
  • Loading branch information
yuhongsun96 authored Dec 28, 2024
1 parent 2203cfa commit fc81a3f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions backend/onyx/connectors/zendesk/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def make_request(self, endpoint: str, params: dict[str, Any]) -> dict[str, Any]:
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()

Expand Down
2 changes: 1 addition & 1 deletion backend/onyx/seeding/load_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions backend/onyx/utils/retry_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@


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
Expand All @@ -33,6 +34,7 @@ def retry_with_default(func: F) -> F:
backoff=backoff,
jitter=jitter,
logger=cast(Logger, logger),
exceptions=exceptions,
)
def wrapped_func(*args: list, **kwargs: dict[str, Any]) -> Any:
return func(*args, **kwargs)
Expand Down

0 comments on commit fc81a3f

Please sign in to comment.