rack-idempotent 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +36 -0
- data/lib/rack-idempotent.rb +0 -2
- data/lib/rack-idempotent/default_rescue.rb +1 -8
- data/lib/rack-idempotent/version.rb +1 -1
- data/spec/rack-idempotent/default_rescue_spec.rb +4 -12
- data/spec/rack-idempotent/exponential_backoff_spec.rb +1 -1
- data/spec/rack-idempotent/immediate_retry_spec.rb +0 -1
- data/spec/rack-idempotent_spec.rb +1 -3
- metadata +1 -2
- data/lib/rack-idempotent/http_exception.rb +0 -10
data/README.md
CHANGED
@@ -49,6 +49,42 @@ client = Rack::Client.new do
|
|
49
49
|
end
|
50
50
|
```
|
51
51
|
|
52
|
+
### Configuration
|
53
|
+
|
54
|
+
### Exponential Backoff
|
55
|
+
|
56
|
+
* Defaults
|
57
|
+
* ```max_retries``` = 5
|
58
|
+
* ```min_retry_interval``` = 0.5 (seconds)
|
59
|
+
* ```max_retry_interval``` = 1800 (seconds)
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
Rack::Client.new do
|
63
|
+
use Rack::Idempotent, {
|
64
|
+
:retry => Rack::Idempotent::ExponentialBackoff.new(
|
65
|
+
:max_retries => 50,
|
66
|
+
:min_retry_interval => 1.0,
|
67
|
+
:max_retry_interval => 30,
|
68
|
+
),
|
69
|
+
}
|
70
|
+
use Rack::Lint
|
71
|
+
run App
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
### Immediate Retry
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
Rack::Client.new do
|
79
|
+
use Rack::Idempotent, {
|
80
|
+
:retry => Rack::Idempotent::ImmediateRetry.new(max_retries: 50),
|
81
|
+
}
|
82
|
+
use Rack::Lint
|
83
|
+
run App
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
|
52
88
|
## Running Tests
|
53
89
|
|
54
90
|
$ bundle exec rake
|
data/lib/rack-idempotent.rb
CHANGED
@@ -11,7 +11,6 @@ class Rack::Idempotent
|
|
11
11
|
autoload :DefaultRescue, 'rack-idempotent/default_rescue'
|
12
12
|
|
13
13
|
# Exceptions
|
14
|
-
autoload :HTTPException, 'rack-idempotent/http_exception'
|
15
14
|
autoload :RetryLimitExceeded, 'rack-idempotent/retry_limit_exceeded'
|
16
15
|
autoload :Retryable, 'rack-idempotent/retryable'
|
17
16
|
|
@@ -33,7 +32,6 @@ class Rack::Idempotent
|
|
33
32
|
|
34
33
|
begin
|
35
34
|
status, headers, body = @app.call(env.dup)
|
36
|
-
raise HTTPException.new(status, headers, body, request) if status >= 400
|
37
35
|
response = Rack::Response.new(body, status, headers)
|
38
36
|
next if rescue_policy.call({:response => response, :request => request})
|
39
37
|
return [status, headers, body]
|
@@ -9,14 +9,7 @@ class Rack::Idempotent::DefaultRescue
|
|
9
9
|
method = nil
|
10
10
|
|
11
11
|
if exception
|
12
|
-
|
13
|
-
return true
|
14
|
-
elsif exception.class == Rack::Idempotent::HTTPException
|
15
|
-
status = exception.status
|
16
|
-
method = exception.request.env["REQUEST_METHOD"]
|
17
|
-
else
|
18
|
-
return false
|
19
|
-
end
|
12
|
+
return IDEMPOTENT_ERROR_CLASSES.include?(exception.class)
|
20
13
|
end
|
21
14
|
|
22
15
|
unless status && method
|
@@ -32,13 +32,8 @@ describe Rack::Idempotent do
|
|
32
32
|
[200, 201, 301, 302, 400, 401, 403, 404, 500].each do |status|
|
33
33
|
it "should not retry GET requests that result in #{status}" do
|
34
34
|
TestCall.errors = [status]
|
35
|
-
|
36
|
-
|
37
|
-
status.should < 400
|
38
|
-
rescue Rack::Idempotent::HTTPException => e
|
39
|
-
e.status.should == status
|
40
|
-
e.status.should >= 400
|
41
|
-
end
|
35
|
+
client.get("http://example.org/")
|
36
|
+
status.should == status
|
42
37
|
RecordRequests.requests.count.should == 1
|
43
38
|
end
|
44
39
|
end
|
@@ -60,11 +55,8 @@ describe Rack::Idempotent do
|
|
60
55
|
it "should not retry POST requests that result in #{status}" do
|
61
56
|
TestCall.errors = [status]
|
62
57
|
begin
|
63
|
-
client.post("http://example.org/")
|
64
|
-
status.should
|
65
|
-
rescue Rack::Idempotent::HTTPException => e
|
66
|
-
e.status.should == status
|
67
|
-
e.status.should >= 400
|
58
|
+
response = client.post("http://example.org/")
|
59
|
+
response.status.should == status
|
68
60
|
end
|
69
61
|
RecordRequests.requests.count.should == 1
|
70
62
|
end
|
@@ -171,9 +171,7 @@ describe Rack::Idempotent do
|
|
171
171
|
|
172
172
|
it 'does not retry a POST if the status is 408' do
|
173
173
|
TestCall.errors = [408]
|
174
|
-
|
175
|
-
client.post("http://example.org/")
|
176
|
-
}.should raise_exception Rack::Idempotent::HTTPException
|
174
|
+
client.post("http://example.org/")
|
177
175
|
|
178
176
|
RecordRequests.requests.count.should == 1
|
179
177
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-idempotent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -28,7 +28,6 @@ files:
|
|
28
28
|
- lib/rack-idempotent.rb
|
29
29
|
- lib/rack-idempotent/default_rescue.rb
|
30
30
|
- lib/rack-idempotent/exponential_backoff.rb
|
31
|
-
- lib/rack-idempotent/http_exception.rb
|
32
31
|
- lib/rack-idempotent/immediate_retry.rb
|
33
32
|
- lib/rack-idempotent/retry_limit_exceeded.rb
|
34
33
|
- lib/rack-idempotent/retryable.rb
|
@@ -1,10 +0,0 @@
|
|
1
|
-
class Rack::Idempotent::HTTPException < StandardError
|
2
|
-
attr_reader :status, :headers, :body, :request
|
3
|
-
def initialize(status, headers, body, request)
|
4
|
-
@status, @headers, @body, @request = status, headers, body, request
|
5
|
-
end
|
6
|
-
|
7
|
-
def to_s
|
8
|
-
@status.to_s
|
9
|
-
end
|
10
|
-
end
|