Refactor the API for retry options #1067
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes the API for specifying retry options to be more customizable while also being more future proof.
Note: the default remains an exponential strategy which should be appropriate for a vast majority of users. Therefore, these APIs will likely only be used by users with very specific needs.
Instead of
RetryOptions
being a transparent struct whose fields the user sets directly (thus making it impossible to extend in the future in a backwards compatible way), the options are now set through methods (e.g.,RetryOptions::exponential
,RetryOptions::fixed
, etc.).Each of these methods takes different set of arguements that are tailored just to the retry strategy at hand. Instead of requiring that the user be confronted with options that might not be relevant to their strategy of choice (e.g., the
max_delay
field had no meaning if the user was using a fixed retry strategy), the options are constrained just to the options that are relevant.This does make instantiation ever so slightly more verbose as you cannot set options directly on the
RetryOptions
. Again, this is a feature not a bug since the options you want to set depend on the overall strategy you choose.Lastly, this adds an additional retry strategy of
custom
that allows users to feed in their ownArc<dyn RetryPolicy>
.Closes #1049