Class: Kurchatov::Queue
- Inherits:
-
Object
- Object
- Kurchatov::Queue
- Defined in:
- lib/kurchatov/queue.rb
Constant Summary collapse
- QUEUE_MAX_SIZE =
10_000
- QUEUE_MAX_FLUSH =
200
Instance Method Summary collapse
- #<<(event) ⇒ Object
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #to_flush ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
8 9 10 |
# File 'lib/kurchatov/queue.rb', line 8 def initialize @events = ::Queue.new end |
Instance Method Details
#<<(event) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/kurchatov/queue.rb', line 12 def <<(event) if @events.size >= QUEUE_MAX_SIZE # GC start if QUEUE_MAX_SIZE ObjectSpace.garbage_collect drop = @events.shift Log.error("Drop event: #{drop.inspect}. See Kurchatov::Queue::QUEUE_MAX_SIZE") end @events << event end |
#to_flush ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kurchatov/queue.rb', line 22 def to_flush cur_events = Array.new count = 0 until @events.empty? cur_events << @events.shift count += 1 break if count > QUEUE_MAX_FLUSH end cur_events end |