Class: Elastictastic::Middleware::Rotor

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/elastictastic/middleware.rb

Defined Under Namespace

Classes: Node

Instance Method Summary collapse

Constructor Details

#initialize(app, *hosts) ⇒ Rotor

Returns a new instance of Rotor.



74
75
76
77
78
79
80
81
82
83
# File 'lib/elastictastic/middleware.rb', line 74

def initialize(app, *hosts)
  first = nil
  hosts.each do |host|
    node = Node.new(app, host)
    first ||= node
    @head.next = node if @head
    @head = node
  end
  @head.next = first
end

Instance Method Details

#call(env) ⇒ Object



85
86
87
88
89
90
91
92
93
94
# File 'lib/elastictastic/middleware.rb', line 85

def call(env)
  last = @head
  begin
    @head = @head.next
    @head.call(env)
  rescue Faraday::Error::ConnectionFailed => e
    raise NoServerAvailable if @head == last
    retry
  end
end