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 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
@@ -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
- if IDEMPOTENT_ERROR_CLASSES.include?(exception.class)
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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Idempotent
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -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
- begin
36
- client.get("http://example.org/")
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 < 400
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
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rack::Idempotent do
4
4
  class SleepMonitor
@@ -15,7 +15,6 @@ describe Rack::Idempotent do
15
15
  describe "using Rack::Idempotent::ImmediateRetry with #{name}" do
16
16
  let(:client) do
17
17
  Rack::Client.new do
18
- use Rack::Lint
19
18
  use Rack::Idempotent, {
20
19
  :retry => Rack::Idempotent::ImmediateRetry.new(opts)
21
20
  }
@@ -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
- lambda {
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.1.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