-
Notifications
You must be signed in to change notification settings - Fork 322
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
Add .retriable feature to Http #598
Conversation
* Delay by default backs backs off over time * Maximum delay time * Exceptions to retry from * Status codes to retry from * Custom retry logic * Respect Retry-After header if present * on_retry callback
I had no time to do a full review, but there's one thing that I would like to be changed. Default list of statuses to retry should be 5XX. So probably for statuses it's better to provide proc. |
@ixti Took your feedback, and made the 500+ range auto retry. However, I would argue that the library should not rely any status code by default. Here is why: When a server is throwing 500 there is a good chance that it is experiencing trouble. By retrying by default we are making the situation worse. The same logic if followed in the faraday gem. |
I'll also wait to to comply with the code climate feedback, until the all human feedback is processed ;) |
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.
I think handling different types of retry statuses is unneeded complication and supporting proc only is more than enough - it will handle all the cases. Also I think exception retry proc and status retry should be separated.
The idea is to allow for a beautiful interface for the developer. HTTP.retriable(retry_statuses: 400..499)
HTTP.retriable(retry_statuses: [404, 500..599]) looks a lot better than HTTP.retriable(retry_statuses: ->(s) { (400..499).cover?(s) })
HTTP.retriable((retry_statuses: ->(s) { s == 404 || (400..499).cover?(s) }) I could move that convienece into
I get that. However one of the options a developer can pass is a proc def perform(client, req)
1.upto(Float::INFINITY) do |attempt| # infinite loop with index
err, res = try_request { yield }
if retry_request?(req, err, res, attempt)
begin
wait_for_retry_or_raise(req, err, res, attempt)
ensure
# ...
client.close
end
elsif err
client.close
raise err
elsif res
return res
end
end
end
def retry_request?(req, err, res, attempt)
if options[:should_retry]
options[:should_retry].call(req, err, res, attempt)
elsif err
options[:exceptions].any? {|err_class| err.is_a?(err_class) }
else
options[:retry_statuses].cover?(req.status)
end
end Would you prefer this? |
* Less procs & proc building overall * seperate delay calculation into its own class
Made some updates!
|
Anything I can do to help progress this PR towards merging? |
This is available now in Pre 5.x releases? |
Any updates on this? @ixti are you still in favor of adding retry functionality to Http? |
The 5.x release is out. If you are still interested in pursuing this, can you rebase? |
I would still love to get this PR merged :-) |
I can try to take a look on this next week. |
That's very kind @ixti ! Thank you. |
Would love to have this. I looked into major changes since it's release and besides the hashrocket one, I don't think anything changed to break this. @ixti would you mind taking a look again? If you want, I can rebase, but I think if I do it, it'd have to go into a new PR |
Sorry been swamped with lots of stuff. Will take a look at the rebased PR as soon as possible. And hope to make it land this month :D |
@ixti any progress? |
This is neat! I would love to get this out of the box. |
I would be okay with merging this if someone fixed the merge conflicts |
Oh hey, sorry about that. Will take a look soon. |
Merged in #775 |
Hurray! It took 1608 days to get the original work by @ixti to make it in. Not the fastest PR to ever get merged, but glad it did and to be a part of it :) |
Based on the great initial POC of @ixti this should complete #595
Remarks: