class Elastictastic::Rotor::Node
Public Class Methods
new(connection, options)
click to toggle source
# File lib/elastictastic/rotor.rb, line 48 def initialize(connection, options) @connection = connection @failures = 0 @backoff_threshold = options[:backoff_threshold] || 0 @backoff_start = options[:backoff_start] @backoff_max = options[:backoff_max] end
Public Instance Methods
request(method, path, body = nil)
click to toggle source
# File lib/elastictastic/rotor.rb, line 56 def request(method, path, body = nil) try_track { @connection.request(method, path, body).tap { succeeded! }} end
Private Instance Methods
available?()
click to toggle source
# File lib/elastictastic/rotor.rb, line 72 def available? !backoff_failures_reached? || !backing_off? end
backing_off?()
click to toggle source
# File lib/elastictastic/rotor.rb, line 77 def backing_off? @back_off_until && @back_off_until > Time.now end
backoff_failures_reached?()
click to toggle source
# File lib/elastictastic/rotor.rb, line 82 def backoff_failures_reached? @failures >= @backoff_threshold end
failed!()
click to toggle source
# File lib/elastictastic/rotor.rb, line 91 def failed! @failures += 1 if @backoff_start && backoff_failures_reached? backoff_count = @failures - @backoff_threshold backoff_interval = @backoff_start * 2 ** backoff_count backoff_interval = @backoff_max if @backoff_max && backoff_interval > @backoff_max @back_off_until = Time.now + backoff_interval end end
succeeded!()
click to toggle source
# File lib/elastictastic/rotor.rb, line 86 def succeeded! @failures = 0 @back_off_until = nil end
try_track() { || ... }
click to toggle source
# File lib/elastictastic/rotor.rb, line 62 def try_track raise NodeUnavailable, "Won't retry this node until #{@back_off_until}" unless available? begin yield rescue ConnectionFailed => e failed! raise e end end