Module: QueueKit::Clients::RoundRobinShuffler
- Includes:
- Instrumentable
- Defined in:
- lib/queue_kit/clients/round_robin_shuffler.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#debug, #default_instrument_options, #default_instrumenter, #enable_debug_mode, #force_debug, #instrument, #instrumenter, #instrumenter_from
Class Method Details
.included(klass) ⇒ Object
6
7
8
9
10
11
12
13
|
# 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
|
Instance Method Details
#client ⇒ Object
30
31
32
33
34
35
36
37
38
|
# 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) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# 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 ⇒ Object
63
64
65
|
# File 'lib/queue_kit/clients/round_robin_shuffler.rb', line 63
def clients
[]
end
|
#commands_per_client ⇒ Object
59
60
61
|
# File 'lib/queue_kit/clients/round_robin_shuffler.rb', line 59
def commands_per_client
@commands_per_client ||= 100
end
|
#rotate_client ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# 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) ⇒ Object
40
41
42
|
# File 'lib/queue_kit/clients/round_robin_shuffler.rb', line 40
def round_robin_from(options)
@commands_per_client = options[:commands_per_client]
end
|