faraday-retry 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +13 -3
- data/lib/faraday/retry/middleware.rb +7 -4
- data/lib/faraday/retry/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2b88675fec154db2d70b835b98124879b77dbcd283b898fea74fe88c1a75a4b
|
4
|
+
data.tar.gz: 57eefe94dd39d192dff652e90cfadda2ce06d244a3a20e849dd9f3df6a88ffb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de85932e530b33168b83399f0135fd862071c10318faaaef324935c3e51bc1914dd9361c68a5c2a6d3a4fc81e9f0193b928a4fe65c2dbc34826998573465af86
|
7
|
+
data.tar.gz: f5e12ca382154fac0fbff872f9f906a62c0a990b06226363c701fa52d05ee927d23b0358f005e6de974e7fad938944beb2621413419b48a5d43b29e4b3180af8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v2.1.1 (2023-02-17)
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
|
7
|
+
* Support for custom RateLimit headers. [PR #13](https://github.com/lostisland/faraday-retry/pull/13). Thanks, [@brookemckim]!
|
8
|
+
|
9
|
+
## v2.1.0 (2023-02-17)
|
10
|
+
|
11
|
+
Invalid release, use v2.1.1.
|
12
|
+
|
3
13
|
## v2.0.0 (2022-06-08)
|
4
14
|
|
5
15
|
### Changed
|
@@ -22,3 +32,4 @@ This release consists of the same middleware that was previously bundled with Fa
|
|
22
32
|
* Retry middleware `retry_block` is not called if retry will not happen due to `max_interval`, https://github.com/lostisland/faraday/pull/1350
|
23
33
|
|
24
34
|
[@maxprokopiev]: https://github.com/maxprokopiev
|
35
|
+
[@brookemckim]: https://github.com/brookemckim
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Faraday Retry
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![CI](https://github.com/lostisland/faraday-retry/actions/workflows/ci.yaml/badge.svg)](https://github.com/lostisland/faraday-retry/actions/workflows/ci.yaml)
|
4
4
|
[![Gem](https://img.shields.io/gem/v/faraday-retry.svg?style=flat-square)](https://rubygems.org/gems/faraday-retry)
|
5
5
|
[![License](https://img.shields.io/github/license/lostisland/faraday-retry.svg?style=flat-square)](LICENSE.md)
|
6
6
|
|
@@ -100,7 +100,7 @@ retry_options = {
|
|
100
100
|
|
101
101
|
Some APIs, like the [Slack API](https://api.slack.com/docs/rate-limits), will inform you when you reach their API limits by replying with a response status code of `429`
|
102
102
|
and a response header of `Retry-After` containing a time in seconds. You should then only retry querying after the amount of time provided by the `Retry-After` header,
|
103
|
-
otherwise you won't get a response. Other APIs communicate their rate limits via the [RateLimit-xxx](https://
|
103
|
+
otherwise you won't get a response. Other APIs communicate their rate limits via the [RateLimit-xxx](https://www.ietf.org/archive/id/draft-ietf-httpapi-ratelimit-headers-05.html#name-providing-ratelimit-fields) headers
|
104
104
|
where `RateLimit-Reset` behaves similarly to the `Retry-After`.
|
105
105
|
|
106
106
|
You can automatically handle both headers and have Faraday pause and retry for the right amount of time by including the `429` status code in the retry statuses list:
|
@@ -111,6 +111,16 @@ retry_options = {
|
|
111
111
|
}
|
112
112
|
```
|
113
113
|
|
114
|
+
If you are working with an API which does not comply with the Rate Limit RFC you can specify custom headers to be used for retry and reset.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
retry_options = {
|
118
|
+
retry_statuses: [429],
|
119
|
+
rate_limit_retry_header: 'x-rate-limit-retry-after',
|
120
|
+
rate_limit_reset_header: 'x-rate-limit-reset'
|
121
|
+
}
|
122
|
+
```
|
123
|
+
|
114
124
|
#### Specify a custom retry logic
|
115
125
|
|
116
126
|
You can also specify a custom retry logic with the `retry_if` option.
|
@@ -142,7 +152,7 @@ For example, you might want to keep track of the response statuses:
|
|
142
152
|
```ruby
|
143
153
|
response_statuses = []
|
144
154
|
retry_options = {
|
145
|
-
retry_block: -> (env:, options:,
|
155
|
+
retry_block: -> (env:, options:, retry_count:, exception:, will_retry_in:) { response_statuses << env.status }
|
146
156
|
}
|
147
157
|
```
|
148
158
|
|
@@ -26,7 +26,8 @@ module Faraday
|
|
26
26
|
:interval_randomness,
|
27
27
|
:backoff_factor, :exceptions,
|
28
28
|
:methods, :retry_if, :retry_block,
|
29
|
-
:retry_statuses
|
29
|
+
:retry_statuses, :rate_limit_retry_header,
|
30
|
+
:rate_limit_reset_header)
|
30
31
|
|
31
32
|
DEFAULT_CHECK = ->(_env, _exception) { false }
|
32
33
|
|
@@ -213,15 +214,17 @@ module Faraday
|
|
213
214
|
end
|
214
215
|
|
215
216
|
# RFC for RateLimit Header Fields for HTTP:
|
216
|
-
# https://
|
217
|
+
# https://www.ietf.org/archive/id/draft-ietf-httpapi-ratelimit-headers-05.html#name-fields-definition
|
217
218
|
def calculate_rate_limit_reset(env)
|
218
|
-
|
219
|
+
reset_header = @options.rate_limit_reset_header || 'RateLimit-Reset'
|
220
|
+
parse_retry_header(env, reset_header)
|
219
221
|
end
|
220
222
|
|
221
223
|
# MDN spec for Retry-After header:
|
222
224
|
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
|
223
225
|
def calculate_retry_after(env)
|
224
|
-
|
226
|
+
retry_header = @options.rate_limit_retry_header || 'Retry-After'
|
227
|
+
parse_retry_header(env, retry_header)
|
225
228
|
end
|
226
229
|
|
227
230
|
def calculate_retry_interval(retries)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-retry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Giuffrida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -157,8 +157,8 @@ licenses:
|
|
157
157
|
- MIT
|
158
158
|
metadata:
|
159
159
|
bug_tracker_uri: https://github.com/lostisland/faraday-retry/issues
|
160
|
-
changelog_uri: https://github.com/lostisland/faraday-retry/blob/v2.
|
161
|
-
documentation_uri: http://www.rubydoc.info/gems/faraday-retry/2.
|
160
|
+
changelog_uri: https://github.com/lostisland/faraday-retry/blob/v2.1.0/CHANGELOG.md
|
161
|
+
documentation_uri: http://www.rubydoc.info/gems/faraday-retry/2.1.0
|
162
162
|
homepage_uri: https://github.com/lostisland/faraday-retry
|
163
163
|
source_code_uri: https://github.com/lostisland/faraday-retry
|
164
164
|
post_install_message:
|