-
Notifications
You must be signed in to change notification settings - Fork 24
Implement Retry Strategy Resolver Pattern with Per-Client Caching #600
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
base: develop
Are you sure you want to change the base?
Conversation
| class RetryStrategyResolver[RS: RetryStrategy](Protocol): | ||
| """Used to resolve a RetryStrategy from retry options.""" | ||
|
|
||
| async def resolve_retry_strategy(self, *, options: RetryStrategyOptions) -> RS: | ||
| """Resolve the retry strategy from the provided options. | ||
| :param options: The retry strategy options to use for creating the strategy. | ||
| """ | ||
| ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other kinds of RetryStrategyResolver are we envisioning? This seems like it only has one real use which is to create a RetryStrategy if one isn't provided.
| """ | ||
|
|
||
| def __init__(self) -> None: | ||
| self._cache: dict[RetryStrategyOptions, RetryStrategy] = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an advantage to us maintaining the cache ourselves vs using something like Python's lru_cache?
Summary
Introduces a resolver pattern for retry strategies that enables per-client caching and state management. This allows multiple operations from the same client to share a single retry strategy instance, which is important for strategies that maintain state across retries such as token buckets and rate limiters.
Motivation
Previously, each operation created its own retry strategy instance, preventing state sharing across operations from the same client. This change implements a resolver-based approach.
Key Changes
RetryStrategyResolverprotocol similar toAuthSchemeResolver. This will be used for objects which will supply clients with retry strategies.CachingRetryStrategyResolverwhich implements the protocol and returns a unique instance of a requested retry strategy object per unique combination of max attempts setting and retry mode setting. This will get called by the client when no RetryStrategy is specified.RetryStrategyOptionsfor users to configure their retry strategy mode and max attempts per client call.