Class: Librato::Metrics::Middleware::Retry

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/librato/metrics/middleware/retry.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, retries = 3) ⇒ Retry



7
8
9
10
# File 'lib/librato/metrics/middleware/retry.rb', line 7

def initialize(app, retries = 3)
  @retries = retries
  super(app)
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/librato/metrics/middleware/retry.rb', line 12

def call(env)
  retries = @retries
  request_body = env[:body]
  begin
    env[:body] = request_body # after failure is set to response body
    @app.call(env)
  rescue Librato::Metrics::ServerError, Timeout::Error,
         Faraday::Error::ConnectionFailed
    if retries > 0
      retries -= 1 and retry
    end
    raise
  end
end