Class: Rudder::Analytics::RetryPolicy
- Inherits:
-
Object
- Object
- Rudder::Analytics::RetryPolicy
show all
- Includes:
- Defaults::Request
- Defined in:
- lib/rudder/analytics/retry_policy.rb
Constant Summary
collapse
- RETRYABLE_ERRORS =
[
Timeout::Error,
EOFError,
IOError,
SocketError,
Errno::ECONNREFUSED,
Errno::ECONNRESET,
Errno::EHOSTUNREACH,
Errno::ENETUNREACH,
Errno::ETIMEDOUT,
Net::OpenTimeout,
Net::ReadTimeout,
Net::ProtocolError,
OpenSSL::SSL::SSLError
].freeze
Defaults::Request::HEADERS, Defaults::Request::HOST, Defaults::Request::MAX_RETRIES, Defaults::Request::PATH, Defaults::Request::PORT, Defaults::Request::RETRIES
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ RetryPolicy
Returns a new instance of RetryPolicy.
50
51
52
53
54
|
# File 'lib/rudder/analytics/retry_policy.rb', line 50
def initialize(options = {})
@max_retries = normalize_max_retries(options)
@respect_retry_after = options.has_key?(:respect_retry_after) ? options[:respect_retry_after] : true
@backoff_policy = options[:backoff_policy] || Rudder::Analytics::BackoffPolicy.new
end
|
Instance Attribute Details
#backoff_policy ⇒ Object
Returns the value of attribute backoff_policy.
30
31
32
|
# File 'lib/rudder/analytics/retry_policy.rb', line 30
def backoff_policy
@backoff_policy
end
|
#max_retries ⇒ Object
Returns the value of attribute max_retries.
30
31
32
|
# File 'lib/rudder/analytics/retry_policy.rb', line 30
def max_retries
@max_retries
end
|
Class Method Details
.backoff_options(config) ⇒ Object
.from_config(config) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/rudder/analytics/retry_policy.rb', line 32
def self.from_config(config)
backoff_policy = config.backoff_policy || Rudder::Analytics::BackoffPolicy.new(backoff_options(config))
new(
:retries => config.retries.nil? ? RETRIES : config.retries,
:respect_retry_after => config.respect_retry_after.nil? ? true : config.respect_retry_after,
:backoff_policy => backoff_policy
)
end
|
Instance Method Details
#max_attempts ⇒ Object
56
57
58
|
# File 'lib/rudder/analytics/retry_policy.rb', line 56
def max_attempts
@max_retries + 1
end
|
#retry_delay_in_seconds(headers = {}) ⇒ Object
68
69
70
71
|
# File 'lib/rudder/analytics/retry_policy.rb', line 68
def retry_delay_in_seconds( = {})
interval = next_backoff_interval(retry_after_delay_in_milliseconds())
interval.to_f / 1000
end
|
#retryable_exception?(exception) ⇒ Boolean
64
65
66
|
# File 'lib/rudder/analytics/retry_policy.rb', line 64
def retryable_exception?(exception)
RETRYABLE_ERRORS.any? { |error_class| exception.is_a?(error_class) }
end
|
#retryable_status_code?(status_code) ⇒ Boolean
60
61
62
|
# File 'lib/rudder/analytics/retry_policy.rb', line 60
def retryable_status_code?(status_code)
status_code.zero? || status_code == 429 || (status_code >= 500 && status_code <= 599)
end
|