rack-idempotent 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack-idempotent/version.rb +1 -1
- data/lib/rack-idempotent.rb +4 -4
- data/spec/rack-idempotent_spec.rb +20 -0
- metadata +4 -4
data/lib/rack-idempotent.rb
CHANGED
@@ -4,17 +4,17 @@ module Rack
|
|
4
4
|
class Idempotent
|
5
5
|
RETRY_LIMIT = 5
|
6
6
|
RETRY_HTTP_CODES = [502, 503, 504]
|
7
|
-
IDEMPOTENT_HTTP_CODES =
|
7
|
+
IDEMPOTENT_HTTP_CODES = RETRY_HTTP_CODES + [408]
|
8
8
|
IDEMPOTENT_ERROR_CLASSES = [Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH]
|
9
9
|
|
10
|
-
class RetryLimitExceeded <
|
10
|
+
class RetryLimitExceeded < StandardError
|
11
11
|
attr_reader :idempotent_exceptions
|
12
12
|
def initialize(idempotent_exceptions)
|
13
13
|
@idempotent_exceptions = idempotent_exceptions
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
class HTTPException <
|
17
|
+
class HTTPException < StandardError
|
18
18
|
attr_reader :status, :headers, :body
|
19
19
|
def initialize(status, headers, body)
|
20
20
|
@status, @headers, @body = status, headers, body
|
@@ -42,7 +42,7 @@ module Rack
|
|
42
42
|
raise HTTPException.new(status, headers, body) if IDEMPOTENT_HTTP_CODES.include?(status)
|
43
43
|
env.merge!(dup_env)
|
44
44
|
[status, headers, body]
|
45
|
-
rescue *IDEMPOTENT_ERROR_CLASSES
|
45
|
+
rescue *(IDEMPOTENT_ERROR_CLASSES + [HTTPException, Retryable]) => ie
|
46
46
|
idempotent_exceptions << ie
|
47
47
|
if env['client.retries'] > RETRY_LIMIT - 1
|
48
48
|
raise(RetryLimitExceeded.new(idempotent_exceptions))
|
@@ -81,6 +81,16 @@ describe Rack::Idempotent do
|
|
81
81
|
env['client.retries'].should == 0
|
82
82
|
end
|
83
83
|
|
84
|
+
it "should be able to rescue http exception via standard error" do
|
85
|
+
RaiseUp.errors = [408]
|
86
|
+
|
87
|
+
begin
|
88
|
+
client.post("/something")
|
89
|
+
rescue => e
|
90
|
+
# works
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
84
94
|
it "should store exceptions raised" do
|
85
95
|
RaiseUp.errors = [502, Errno::ECONNREFUSED, 408, 504, Errno::EHOSTUNREACH, Errno::ETIMEDOUT]
|
86
96
|
errors = RaiseUp.errors.dup
|
@@ -97,4 +107,14 @@ describe Rack::Idempotent do
|
|
97
107
|
exception.idempotent_exceptions.map{|ie| ie.is_a?(Rack::Idempotent::HTTPException) ? ie.status : ie.class}.should == errors
|
98
108
|
end
|
99
109
|
|
110
|
+
it "should be able to rescue retry limit exceeded via standard error" do
|
111
|
+
RaiseUp.errors = (0...Rack::Idempotent::RETRY_LIMIT.succ).map{|_| 503 }
|
112
|
+
|
113
|
+
begin
|
114
|
+
res = client.get("/doesntmatter")
|
115
|
+
rescue => e
|
116
|
+
# works
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
100
120
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-idempotent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ines Sombra
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-
|
18
|
+
date: 2012-02-09 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: Retry logic for rack-client
|