Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Retryable Exceptions #196

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions aana/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ def __init__(
name (str, optional): The name of the application. Defaults to "app".
migration_func (Callable | None): The migration function to run. Defaults to None.
retryable_exceptions (list[Exception, str] | None): The exceptions that can be retried in the task queue.
Defaults to ['InferenceException'].
Defaults to ['InferenceException', 'ActorDiedError', 'OutOfMemoryError'].
"""
self.name = name
self.migration_func = migration_func
self.endpoints: dict[str, Endpoint] = {}
self.deployments: dict[str, Deployment] = {}

if retryable_exceptions is None:
self.retryable_exceptions = [InferenceException]
self.retryable_exceptions = [
"InferenceException",
"ActorDiedError",
"OutOfMemoryError",
]
else:
self.retryable_exceptions = retryable_exceptions
# Convert exceptions to string if they are not already
Expand Down
4 changes: 3 additions & 1 deletion aana/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ async def sleep_exponential_backoff(
attempts (int): The number of attempts so far.
jitter (bool): Whether to add jitter to the delay. Default is True.
"""
delay = min(initial_delay * (2**attempts), max_delay)
# Prevent overflow by using min(attempt, 32) since 2^32 is already huge
capped_attempt = min(attempts, 32)
delay = min(initial_delay * (2**capped_attempt), max_delay)
# Full jitter
delay_with_jitter = random.uniform(0, delay) if jitter else delay # noqa: S311
await asyncio.sleep(delay_with_jitter)
Loading