module QueueKit::Clients::RoundRobinShuffler

Public Class Methods

included(klass) click to toggle source
Calls superclass method
# File lib/queue_kit/clients/round_robin_shuffler.rb, line 6
def self.included(klass)
  super(klass)
  klass.class_eval do
    def command_clients_size
      @clients.size
    end
  end
end

Public Instance Methods

client() click to toggle source
# File lib/queue_kit/clients/round_robin_shuffler.rb, line 30
def client
  @client_command_count += 1

  if @client_command_count > commands_per_client
    rotate_client
  end

  @current_client
end
client_command_with_retries(retries = 10) { |client, attempts)| ... } click to toggle source
# File lib/queue_kit/clients/round_robin_shuffler.rb, line 15
def client_command_with_retries(retries = 10)
  attempts = 0

  while attempts < retries
    if data = (yield client, attempts)
      return data
    end

    rotate_client
    attempts += 1
  end

  nil
end
clients() click to toggle source
# File lib/queue_kit/clients/round_robin_shuffler.rb, line 63
def clients
  []
end
command_clients_size() click to toggle source
# File lib/queue_kit/clients/round_robin_shuffler.rb, line 9
def command_clients_size
  @clients.size
end
commands_per_client() click to toggle source
# File lib/queue_kit/clients/round_robin_shuffler.rb, line 59
def commands_per_client
  @commands_per_client ||= 100
end
rotate_client() click to toggle source
# File lib/queue_kit/clients/round_robin_shuffler.rb, line 44
def rotate_client
  instrument "queue.rotate_client"
  @client_index ||= -1
  @client_len ||= clients.size

  @client_command_count = 0
  @client_index += 1

  if @client_index >= @client_len
    @client_index = 0
  end

  @current_client = clients[@client_index]
end
round_robin_from(options) click to toggle source
# File lib/queue_kit/clients/round_robin_shuffler.rb, line 40
def round_robin_from(options)
  @commands_per_client = options[:commands_per_client]
end