mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-30 14:39:55 +02:00
@@ -40,6 +40,13 @@ class ZendeskClient:
|
|||||||
response = requests.get(
|
response = requests.get(
|
||||||
f"{self.base_url}/{endpoint}", auth=self.auth, params=params
|
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()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
@@ -216,7 +216,7 @@ def seed_initial_documents(
|
|||||||
# Retries here because the index may take a few seconds to become ready
|
# 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
|
# 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)
|
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
|
# Mock a run for the UI even though it did not actually call out to anything
|
||||||
|
@@ -15,11 +15,12 @@ F = TypeVar("F", bound=Callable[..., Any])
|
|||||||
|
|
||||||
|
|
||||||
def retry_builder(
|
def retry_builder(
|
||||||
tries: int = 10,
|
tries: int = 20,
|
||||||
delay: float = 0.1,
|
delay: float = 0.1,
|
||||||
max_delay: float | None = None,
|
max_delay: float | None = 60,
|
||||||
backoff: float = 2,
|
backoff: float = 2,
|
||||||
jitter: tuple[float, float] | float = 1,
|
jitter: tuple[float, float] | float = 1,
|
||||||
|
exceptions: type[Exception] | tuple[type[Exception], ...] = (Exception,),
|
||||||
) -> Callable[[F], F]:
|
) -> Callable[[F], F]:
|
||||||
"""Builds a generic wrapper/decorator for calls to external APIs that
|
"""Builds a generic wrapper/decorator for calls to external APIs that
|
||||||
may fail due to rate limiting, flakes, or other reasons. Applies exponential
|
may fail due to rate limiting, flakes, or other reasons. Applies exponential
|
||||||
@@ -33,6 +34,7 @@ def retry_builder(
|
|||||||
backoff=backoff,
|
backoff=backoff,
|
||||||
jitter=jitter,
|
jitter=jitter,
|
||||||
logger=cast(Logger, logger),
|
logger=cast(Logger, logger),
|
||||||
|
exceptions=exceptions,
|
||||||
)
|
)
|
||||||
def wrapped_func(*args: list, **kwargs: dict[str, Any]) -> Any:
|
def wrapped_func(*args: list, **kwargs: dict[str, Any]) -> Any:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
Reference in New Issue
Block a user