Class: Rack::Idempotent::ImmediateRetry

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-idempotent/immediate_retry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ImmediateRetry

Returns a new instance of ImmediateRetry.



4
5
6
# File 'lib/rack-idempotent/immediate_retry.rb', line 4

def initialize(options={})
  @max_retries = options[:max_retries] || Rack::Idempotent::DEFAULT_RETRY_LIMIT
end

Instance Attribute Details

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



2
3
4
# File 'lib/rack-idempotent/immediate_retry.rb', line 2

def max_retries
  @max_retries
end

Instance Method Details

#call(request, response, exception) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/rack-idempotent/immediate_retry.rb', line 8

def call(request, response, exception)
  request.env["idempotent.requests.count"] ||= 0
  request.env["idempotent.requests.count"] += 1

  if request.env["idempotent.requests.count"] >= max_retries
    raise Rack::Idempotent::RetryLimitExceeded.new(
      request.env["idempotent.requests.exceptions"]
    )
  end
end