Class: Cottus::RoundRobinStrategy

Inherits:
Strategy
  • Object
show all
Defined in:
lib/cottus/strategies.rb

Direct Known Subclasses

RetryableRoundRobinStrategy

Instance Method Summary collapse

Constructor Details

#initialize(connections, options = {}) ⇒ RoundRobinStrategy

Returns a new instance of RoundRobinStrategy.



24
25
26
27
28
29
# File 'lib/cottus/strategies.rb', line 24

def initialize(connections, options={})
  super

  @index = 0
  @mutex = Mutex.new
end

Instance Method Details

#execute(meth, path, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cottus/strategies.rb', line 31

def execute(meth, path, options={})
  tries = 0

  begin
    next_connection.send(meth, path, options)
  rescue *VALID_EXCEPTIONS => e
    if tries >= @connections.count
      raise e
    else
      tries += 1
      retry
    end
  end
end