class Makara::Strategies::PriorityFailover

Public Instance Methods

connection_added(wrapper) click to toggle source
# File lib/makara/strategies/priority_failover.rb, line 9
def connection_added(wrapper)
  # insert in weighted order
  @weighted_connections.each_with_index do |con, index|
    if wrapper._makara_weight > con._makara_weight
      @weighted_connections.insert(index, wrapper)
      return
    end
  end

  # else at end
  @weighted_connections << wrapper
end
current() click to toggle source
# File lib/makara/strategies/priority_failover.rb, line 22
def current
  safe_value(@current_idx)
end
init() click to toggle source
# File lib/makara/strategies/priority_failover.rb, line 4
def init
  @current_idx = 0
  @weighted_connections = []
end
next() click to toggle source
# File lib/makara/strategies/priority_failover.rb, line 26
def next
  @weighted_connections.each_with_index do |con, index|
    check = safe_value(index)
    next unless check

    @current_idx = index
    return check
  end

  nil
end
safe_value(idx) click to toggle source

return the connection if it's not blacklisted otherwise return nil optionally, store the position and context we're returning

# File lib/makara/strategies/priority_failover.rb, line 41
def safe_value(idx)
  con = @weighted_connections[idx]
  return nil unless con
  return nil if con._makara_blacklisted?

  con
end