-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Do not warn even if faraday-retry gem is missing #1706
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -6,14 +6,6 @@ | |
require 'octokit/version' | ||
require 'octokit/warnable' | ||
|
||
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0') | ||
begin | ||
require 'faraday/retry' | ||
rescue LoadError | ||
Octokit::Warnable.octokit_warn 'To use retry middleware with Faraday v2.0+, install `faraday-retry` gem' | ||
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. This warning is the only thing that would even let you know that this gem does retries. There is nothing in the README about this. This would be better as an explicit option to enable retries. 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. So do you suggest disabling retries by default? 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. That would be the best way to remove the warning. The retry functionality needs to be better documented. 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. |
||
end | ||
end | ||
|
||
module Octokit | ||
# Default configuration options for {Client} | ||
module Default | ||
|
@@ -31,16 +23,6 @@ module Default | |
|
||
# Default Faraday middleware stack | ||
MIDDLEWARE = Faraday::RackBuilder.new do |builder| | ||
# In Faraday 2.x, Faraday::Request::Retry was moved to a separate gem | ||
# so we use it only when it's available. | ||
if defined?(Faraday::Request::Retry) | ||
retry_exceptions = Faraday::Request::Retry::DEFAULT_EXCEPTIONS + [Octokit::ServerError] | ||
builder.use Faraday::Request::Retry, exceptions: retry_exceptions | ||
elsif defined?(Faraday::Retry::Middleware) | ||
retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Octokit::ServerError] | ||
builder.use Faraday::Retry::Middleware, exceptions: retry_exceptions | ||
end | ||
|
||
builder.use Octokit::Middleware::FollowRedirects | ||
builder.use Octokit::Response::RaiseError | ||
builder.use Octokit::Response::FeedParser | ||
|
@@ -147,7 +129,7 @@ def login | |
# from {MIDDLEWARE} | ||
# @return [Faraday::RackBuilder or Faraday::Builder] | ||
def middleware | ||
MIDDLEWARE | ||
MIDDLEWARE.dup | ||
end | ||
|
||
# Default GitHub password for Basic Auth from ENV | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Octokit | ||
module Middleware | ||
base = if defined?(Faraday::Request::Retry) | ||
Faraday::Request::Retry | ||
else | ||
require 'faraday/retry' | ||
Faraday::Retry::Middleware | ||
end | ||
|
||
# Public: Retries each request a limited number of times. | ||
class Retry < base | ||
def initialize(app, **kwargs) | ||
super(app, **kwargs, exceptions: DEFAULT_EXCEPTIONS + [Octokit::ServerError]) | ||
end | ||
end | ||
end | ||
end |
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 would think configuring it on the client would be better
and then in the connection sawyer options you can insert the retry middleware if @auto_retry
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.
While having a parameter for
Octokit::Client.new
is more concise, there are a few advantages of explicitly requiring to interact with middleware:README.md
.So there is some trade-off. What do you prefer?
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 happens if you want one client that retries and another that doesn't. Setting on Octokit.middleware is global.
You probably also want a maintainer to chime in here...
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.
You can also configure an individual instance; see: https://github.com/octokit/octokit.rb/pull/1706/files#diff-7ee18df1929eee9ac41b3ffa5f60cc4904aeb944ff7be6034721b1a76dc2798dR520