-
Notifications
You must be signed in to change notification settings - Fork 330
improve flexiblity of retry policy #584
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
Changes from 5 commits
a73146a
b585e5e
9b2aaf1
890f895
72a063b
cf281c8
ec17eb4
b8538bf
9a71523
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,7 @@ use std::future::Future; | |||||
| /// impl<E> Policy<Req, Res, E> for Attempts { | ||||||
| /// type Future = future::Ready<Self>; | ||||||
| /// | ||||||
| /// fn retry(&self, req: &Req, result: Result<&Res, &E>) -> Option<Self::Future> { | ||||||
| /// fn retry(&self, req: &mut Req, result: &mut Result<Res, E>) -> Option<Self::Future> { | ||||||
| /// match result { | ||||||
| /// Ok(_) => { | ||||||
| /// // Treat all `Response`s as success, | ||||||
|
|
@@ -56,9 +56,24 @@ pub trait Policy<Req, Res, E>: Sized { | |||||
| /// If the request *should* be retried, return `Some` future of a new | ||||||
| /// policy that would apply for the next request attempt. | ||||||
| /// | ||||||
| /// ## Mutating Requests | ||||||
| /// | ||||||
| /// The policy MAY chose to mutate the `req`: if the request is mutated, the mutated request | ||||||
| /// will be sent to the inner service in the next retry. This can be helpful for use cases like | ||||||
| /// tracking the retry count in a header. | ||||||
| /// | ||||||
| /// ## Mutating Results | ||||||
| /// | ||||||
| /// The policy MAY chose to mutate the result. This can enable the retry policy to convert a failure | ||||||
| /// into a success and vice versa. For example, if the policy is used to poll while waiting for a state | ||||||
| /// change, you can switch the result to failure such that running out of retries returns a specific failure. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: in general, we prefer to avoid second-person ('you') language in docs:
Suggested change
|
||||||
| /// | ||||||
| /// You can also record metadata on the request to include information about the number of retries required | ||||||
| /// or to record that a failure failed after exhausting all retries. | ||||||
|
rcoh marked this conversation as resolved.
Outdated
rcoh marked this conversation as resolved.
Outdated
|
||||||
| /// | ||||||
| /// [`Service::Response`]: crate::Service::Response | ||||||
| /// [`Service::Error`]: crate::Service::Error | ||||||
| fn retry(&self, req: &Req, result: Result<&Res, &E>) -> Option<Self::Future>; | ||||||
| fn retry(&self, req: &mut Req, result: &mut Result<Res, E>) -> Option<Self::Future>; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess getting a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, that is a really good point david, what do you think about that @rcoh ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment wasn't threaded because of email:
|
||||||
|
|
||||||
| /// Tries to clone a request before being passed to the inner service. | ||||||
| /// | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.