Class: Eventboss::Polling::TimedRoundRobin
- Inherits:
-
Object
- Object
- Eventboss::Polling::TimedRoundRobin
- Defined in:
- lib/eventboss/polling/timed_round_robin.rb
Constant Summary collapse
- PAUSE_AFTER_EMPTY =
seconds
2
Instance Method Summary collapse
-
#initialize(queues, timer = Time) ⇒ TimedRoundRobin
constructor
A new instance of TimedRoundRobin.
- #messages_found(queue, messages_count) ⇒ Object
- #next_queue ⇒ Object
Constructor Details
#initialize(queues, timer = Time) ⇒ TimedRoundRobin
Returns a new instance of TimedRoundRobin.
6 7 8 9 10 11 12 13 |
# File 'lib/eventboss/polling/timed_round_robin.rb', line 6 def initialize(queues, timer = Time) @queues = queues.to_a @timer = timer @next_queue_index = 0 @paused_until = @queues.each_with_object(Hash.new) do |queue, hash| hash[queue] = @timer.at(0) end end |
Instance Method Details
#messages_found(queue, messages_count) ⇒ Object
26 27 28 |
# File 'lib/eventboss/polling/timed_round_robin.rb', line 26 def (queue, ) pause(queue) if == 0 end |
#next_queue ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/eventboss/polling/timed_round_robin.rb', line 15 def next_queue size = @queues.length size.times do queue = @queues[@next_queue_index] @next_queue_index = (@next_queue_index + 1) % size return queue unless queue_paused?(queue) end nil end |