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

Returns a new instance of Retry.



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

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

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  retries = @retries
  begin
    @app.call(env)
  rescue Librato::Metrics::ServerError, Timeout::Error
    if retries > 0
      retries -= 1 and retry
    end
    raise
  end
end