Class: LHC::Retry

Inherits:
Interceptor show all
Defined in:
lib/lhc/interceptors/retry.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Interceptor

#request

Instance Method Summary collapse

Methods inherited from Interceptor

#after_request, #all_interceptor_classes, #before_raw_request, #before_request, #before_response, dup, #initialize, #response

Constructor Details

This class inherits a constructor from LHC::Interceptor

Class Attribute Details

.allObject

Returns the value of attribute all.



7
8
9
# File 'lib/lhc/interceptors/retry.rb', line 7

def all
  @all
end

.maxObject

Returns the value of attribute max.



7
8
9
# File 'lib/lhc/interceptors/retry.rb', line 7

def max
  @max
end

Instance Attribute Details

#current_retryObject

Returns the value of attribute current_retry.



4
5
6
# File 'lib/lhc/interceptors/retry.rb', line 4

def current_retry
  @current_retry
end

#retriesObject

Returns the value of attribute retries.



4
5
6
# File 'lib/lhc/interceptors/retry.rb', line 4

def retries
  @retries
end

Instance Method Details

#after_responseObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lhc/interceptors/retry.rb', line 10

def after_response
  response.request.options[:retries] ||= 0
  return unless retry?(response.request)

  response.request.options[:retries] += 1
  current_retry = response.request.options[:retries]
  begin
    response.request.run!
  rescue LHC::Error
    return
  end
  response.request.response if current_retry == response.request.options[:retries]
end