faraday_middleware-request-retry 0.0.2 → 0.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 +4 -0
- data/README.md +13 -2
- data/lib/faraday_middleware-request-retry.rb +1 -1
- data/lib/faraday_middleware-request-retry/retry.rb +11 -7
- data/test/test_setup.rb +4 -5
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aa9342c9636f4ecd594b79f8bbf40efe64c5092
|
4
|
+
data.tar.gz: ae7a148dcce1ecbcb12e5801f66f2242f997b4bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9febff9858f8c17495793773ebc4d75c1469c959f47d1813dedee59f75ae60a77d266848aca3938492d5736b457cee14ad8a3a1270c5cbba05fc149888923f74
|
7
|
+
data.tar.gz: 1d7cd9529a89f91b0ac492bc367da09e85db67a83322d4347afcf53c28885bce7c8dcd6a13bd275c3426649f0d6023c0755c1f147e3ed54fb0704c5fc0475d30
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -5,6 +5,7 @@ FaradayMiddleware::Request::Retry
|
|
5
5
|
[![Build Status][build-status-svg]][build-status-link]
|
6
6
|
[![Coverage Status][coverage-status-svg]][coverage-status-link]
|
7
7
|
[![Dependency Status][dependency-status-svg]][dependency-status-link]
|
8
|
+
[![Codacy Badge][codacy-svg]][codacy-link]
|
8
9
|
[![Code Climate][codeclimate-status-svg]][codeclimate-status-link]
|
9
10
|
[![Scrutinizer Code Quality][scrutinizer-status-svg]][scrutinizer-status-link]
|
10
11
|
[![Downloads][downloads-svg]][downloads-link]
|
@@ -45,13 +46,21 @@ require 'faraday_middleware-request-retry'
|
|
45
46
|
require 'logger'
|
46
47
|
|
47
48
|
conn = Faraday.new(url: "http://example.com") do |builder|
|
48
|
-
builder.use FaradayMiddleware::Refresh::Retry, logger: Logger.new(STDOUT)
|
49
|
+
builder.use FaradayMiddleware::Refresh::Retry, logger: Logger.new(STDOUT), retry_after: 15
|
49
50
|
builder.adapter Faraday.default_adapter
|
50
51
|
end
|
51
52
|
|
52
53
|
conn.get "/foo" # sends token
|
53
54
|
```
|
54
55
|
|
56
|
+
Options include:
|
57
|
+
|
58
|
+
| Option | Values | Optional | Default |
|
59
|
+
|--------|--------|----------|---------|
|
60
|
+
| `:logger` | `Logger` object | optional |
|
61
|
+
| `:retry_after` | Default retry seconds | optional | `10` seconds |
|
62
|
+
| `:error_codes` | Array of error codes, e.g. `[429, 503, 504]` | optional | `[429, 503]` |
|
63
|
+
|
55
64
|
## Change Log
|
56
65
|
|
57
66
|
See [CHANGELOG.md](CHANGELOG.md)
|
@@ -70,7 +79,7 @@ Please report these on [Github](https://github.com/grokify/faraday_middleware-re
|
|
70
79
|
|
71
80
|
## Credits
|
72
81
|
|
73
|
-
This
|
82
|
+
This library is originally based on code extracted from the Zendesk Ruby SDK's `ZendeskAPI::Middleware::Request::Retry` class, in [v1.14.0](https://github.com/zendesk/zendesk_api_client_rb/releases/tag/v1.14.0) (commit [2c2b52e](https://github.com/zendesk/zendesk_api_client_rb/blob/2c2b52ea390b3641d4af383759217fda75bc74ec/LICENSE)) available under the Apache 2.0 license.
|
74
83
|
|
75
84
|
## Copyright and license
|
76
85
|
|
@@ -94,6 +103,8 @@ Unless required by applicable law or agreed to in writing, software distributed
|
|
94
103
|
[coverage-status-link]: https://coveralls.io/r/grokify/faraday_middleware-request-retry?branch=master
|
95
104
|
[dependency-status-svg]: https://gemnasium.com/grokify/faraday_middleware-request-retry.svg
|
96
105
|
[dependency-status-link]: https://gemnasium.com/grokify/faraday_middleware-request-retry
|
106
|
+
[codacy-svg]: https://api.codacy.com/project/badge/Grade/d2c515165a60402eb10410cf4bd51f50
|
107
|
+
[codacy-link]: https://www.codacy.com/app/grokify/faraday_middleware-request-retry
|
97
108
|
[codeclimate-status-svg]: https://codeclimate.com/github/grokify/faraday_middleware-request-retry/badges/gpa.svg
|
98
109
|
[codeclimate-status-link]: https://codeclimate.com/github/grokify/faraday_middleware-request-retry
|
99
110
|
[scrutinizer-status-svg]: https://scrutinizer-ci.com/g/grokify/faraday_middleware-request-retry/badges/quality-score.png?b=master
|
@@ -1 +1 @@
|
|
1
|
-
require 'faraday_middleware-request-retry/retry'
|
1
|
+
require 'faraday_middleware-request-retry/retry'
|
@@ -7,17 +7,22 @@ module FaradayMiddleware
|
|
7
7
|
DEFAULT_RETRY_AFTER = 10
|
8
8
|
ERROR_CODES = [429, 503]
|
9
9
|
|
10
|
+
attr_reader :error_codes
|
11
|
+
attr_reader :retry_after
|
12
|
+
|
10
13
|
def initialize(app, options = {})
|
11
|
-
super
|
14
|
+
super app
|
12
15
|
@logger = options[:logger]
|
16
|
+
@error_codes = options[:error_codes] || ERROR_CODES
|
17
|
+
@retry_after = options[:retry_after] || DEFAULT_RETRY_AFTER
|
13
18
|
end
|
14
19
|
|
15
20
|
def call(env)
|
16
21
|
original_env = env.dup
|
17
|
-
response = @app.call
|
22
|
+
response = @app.call env
|
18
23
|
|
19
|
-
if
|
20
|
-
seconds_left = (response.env[:response_headers][:retry_after] ||
|
24
|
+
if @error_codes.include? response.env[:status]
|
25
|
+
seconds_left = (response.env[:response_headers][:retry_after] || @retry_after).to_i
|
21
26
|
@logger.warn "You have been rate limited. Retrying in #{seconds_left} seconds..." if @logger
|
22
27
|
|
23
28
|
seconds_left.times do |i|
|
@@ -26,9 +31,8 @@ module FaradayMiddleware
|
|
26
31
|
@logger.warn "#{time_left}..." if time_left > 0 && time_left % 5 == 0 && @logger
|
27
32
|
end
|
28
33
|
|
29
|
-
@logger.warn
|
30
|
-
|
31
|
-
@app.call(original_env)
|
34
|
+
@logger.warn 'Retrying...' if @logger
|
35
|
+
@app.call original_env
|
32
36
|
else
|
33
37
|
response
|
34
38
|
end
|
data/test/test_setup.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
require 'coveralls'
|
2
2
|
Coveralls.wear!
|
3
3
|
|
4
|
-
require 'test/unit'
|
5
4
|
require 'faraday'
|
6
5
|
require 'faraday_middleware'
|
7
6
|
require 'faraday_middleware-request-retry'
|
7
|
+
require 'test/unit'
|
8
8
|
|
9
9
|
class RetryTest < Test::Unit::TestCase
|
10
|
-
def
|
11
|
-
|
10
|
+
def test_setup
|
12
11
|
@conn = Faraday.new 'http://example.com/api' do |builder|
|
13
12
|
builder.use FaradayMiddleware::Request::Retry
|
14
13
|
end
|
15
|
-
|
14
|
+
assert_equal 'FaradayMiddleware::Request::Retry', @conn.builder.app.class.name
|
16
15
|
end
|
17
|
-
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday_middleware-request-retry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '0'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '0
|
22
|
+
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0
|
29
|
+
version: '0'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0
|
32
|
+
version: '0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: faraday_middleware
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +121,7 @@ files:
|
|
121
121
|
- test/test_setup.rb
|
122
122
|
homepage: https://github.com/grokify/
|
123
123
|
licenses:
|
124
|
-
- Apache
|
124
|
+
- Apache-2.0
|
125
125
|
metadata: {}
|
126
126
|
post_install_message:
|
127
127
|
rdoc_options: []
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.5.2
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: Faraday request middleware with retry
|