Skip to content

Commit 4fb5084

Browse files
committed
change retries_remaining retry_block arg to retry_count (O-based, incrementing)
1 parent ffef0dd commit 4fb5084

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Changed
66

77
* retry_block now takes keyword arguments instead of positional (backwards incompatible)
8+
* retry_block `retry_count` arg now counts up from 0, instead of old `retries_remaining`
89

910
### Added
1011

lib/faraday/retry/middleware.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ def retry_statuses
108108
# every retry. The block will be yielded keyword arguments:
109109
# * env [Faraday::Env]: Request environment
110110
# * options [Faraday::Options]: middleware options
111-
# * retries_remaining [Integer]: how many more possible retries are
112-
# remaining
111+
# * retry_count [Integer]: how many retries have already occured (starts at 0)
113112
# * exception [Exception]: exception that triggered the retry,
114113
# will be the synthetic `Faraday::RetriableResponse` if the
115114
# retry was triggered by something other than an exception.
@@ -157,7 +156,7 @@ def call(env)
157156
@options.retry_block.call(
158157
env: env,
159158
options: @options,
160-
retries_remaining: retries,
159+
retry_count: @options.max - (retries + 1),
161160
exception: e,
162161
will_retry_in: sleep_amount
163162
)

spec/faraday/retry/middleware_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@
9999
expect(retry_block_calls.first[:exception]).to be_kind_of(Errno::ETIMEDOUT)
100100
expect(retry_block_calls.first[:options]).to be_kind_of(Faraday::Options)
101101
expect(retry_block_calls.first[:env]).to be_kind_of(Faraday::Env)
102-
expect(retry_block_calls.first[:will_retry_in]).to be_kind_of(Float)
103-
expect(retry_block_calls.first[:retries_remaining]).to eq 1
102+
expect(retry_block_calls.first[:retry_count]).to be_kind_of(Integer)
103+
expect(retry_block_calls.first[:retry_count]).to eq 0
104+
end
105+
106+
it "increments retry_count" do
107+
expect(retry_block_calls[1][:retry_count]).to eq 1
104108
end
105109
end
106110
end

0 commit comments

Comments
 (0)