Class: Octopus::LoadBalancing::RoundRobin

Inherits:
Object
  • Object
show all
Defined in:
lib/octopus/load_balancing/round_robin.rb

Instance Method Summary collapse

Constructor Details

#initialize(slaves_list) ⇒ RoundRobin

Returns a new instance of RoundRobin.

Raises:



8
9
10
11
12
# File 'lib/octopus/load_balancing/round_robin.rb', line 8

def initialize(slaves_list)
  raise Octopus::Exception.new("No slaves available") if slaves_list.empty?
  @slaves_list = slaves_list
  @slave_index = 0
end

Instance Method Details

#next(options) ⇒ Object

Returns the next available slave in the pool



15
16
17
# File 'lib/octopus/load_balancing/round_robin.rb', line 15

def next(options)
  @slaves_list[@slave_index = (@slave_index + 1) % @slaves_list.length]
end