mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
Don't call retry_block if retry won't happen due to max_interval and retry_after (#1350)
This commit is contained in:
parent
a555580f5f
commit
b1165eac65
@ -38,7 +38,7 @@ We did our best to make this transition as painless as possible for you, so here
|
|||||||
* If you're relying on `Faraday.default_adapter` (e.g. if you use `Faraday.get` or other verb class methods, or not
|
* If you're relying on `Faraday.default_adapter` (e.g. if you use `Faraday.get` or other verb class methods, or not
|
||||||
specifying an adapter in your connection initializer), then you'll now need to set it yourself. It previously
|
specifying an adapter in your connection initializer), then you'll now need to set it yourself. It previously
|
||||||
defaulted to `:net_http`, but it now defaults to `:test`. You can do so simply by using the setter:
|
defaulted to `:net_http`, but it now defaults to `:test`. You can do so simply by using the setter:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# For example, to use net_http (previous default value, will now require `gem 'faraday-net_http'` in your gemfile)
|
# For example, to use net_http (previous default value, will now require `gem 'faraday-net_http'` in your gemfile)
|
||||||
Faraday.default_adapter = :net_http
|
Faraday.default_adapter = :net_http
|
||||||
@ -86,6 +86,7 @@ For more details, see https://github.com/lostisland/faraday/pull/1306
|
|||||||
* Remove `Faraday::Response::Middleware`. You can now use the new `on_complete` callback provided by `Faraday::Middleware`.
|
* Remove `Faraday::Response::Middleware`. You can now use the new `on_complete` callback provided by `Faraday::Middleware`.
|
||||||
* Drop `Faraday::UploadIO` in favour of `Faraday::FilePart`.
|
* Drop `Faraday::UploadIO` in favour of `Faraday::FilePart`.
|
||||||
* `Faraday.default_connection_options` will now be deep-merged into new connections to avoid overriding them (e.g. headers).
|
* `Faraday.default_connection_options` will now be deep-merged into new connections to avoid overriding them (e.g. headers).
|
||||||
|
* Retry middleware `retry_block` is not called if retry will not happen due to `max_interval`. (#1350)
|
||||||
|
|
||||||
## Faraday 1.0
|
## Faraday 1.0
|
||||||
|
|
||||||
|
@ -154,8 +154,8 @@ module Faraday
|
|||||||
if retries.positive? && retry_request?(env, e)
|
if retries.positive? && retry_request?(env, e)
|
||||||
retries -= 1
|
retries -= 1
|
||||||
rewind_files(request_body)
|
rewind_files(request_body)
|
||||||
@options.retry_block.call(env, @options, retries, e)
|
|
||||||
if (sleep_amount = calculate_sleep_amount(retries + 1, env))
|
if (sleep_amount = calculate_sleep_amount(retries + 1, env))
|
||||||
|
@options.retry_block.call(env, @options, retries, e)
|
||||||
sleep sleep_amount
|
sleep sleep_amount
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
@ -85,6 +85,16 @@ RSpec.describe Faraday::Request::Retry do
|
|||||||
|
|
||||||
it { expect(Time.now - @started).to be_within(0.04).of(0.2) }
|
it { expect(Time.now - @started).to be_within(0.04).of(0.2) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'and retry_block is set' do
|
||||||
|
let(:options) { [{ retry_block: ->(env, options, retries, exc) { retry_block_calls << [env, options, retries, exc] } }] }
|
||||||
|
let(:retry_block_calls) { [] }
|
||||||
|
let(:retry_block_times_called) { retry_block_calls.size }
|
||||||
|
|
||||||
|
it 'calls retry block for each retry' do
|
||||||
|
expect(retry_block_times_called).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when no exception raised' do
|
context 'when no exception raised' do
|
||||||
@ -249,6 +259,24 @@ RSpec.describe Faraday::Request::Retry do
|
|||||||
let(:options) { [{ max: 2, interval: 0.1, max_interval: 5, retry_statuses: 504 }] }
|
let(:options) { [{ max: 2, interval: 0.1, max_interval: 5, retry_statuses: 504 }] }
|
||||||
|
|
||||||
it { expect(times_called).to eq(1) }
|
it { expect(times_called).to eq(1) }
|
||||||
|
|
||||||
|
context 'and retry_block is set' do
|
||||||
|
let(:options) do
|
||||||
|
[{
|
||||||
|
retry_block: ->(env, options, retries, exc) { retry_block_calls << [env, options, retries, exc] },
|
||||||
|
max: 2,
|
||||||
|
max_interval: 5,
|
||||||
|
retry_statuses: 504
|
||||||
|
}]
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:retry_block_calls) { [] }
|
||||||
|
let(:retry_block_times_called) { retry_block_calls.size }
|
||||||
|
|
||||||
|
it 'retry_block is not called' do
|
||||||
|
expect(retry_block_times_called).to eq(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user