Sha256: e97a7d4a1477955a532d20e2ade07dcd068dae6ffa06deee39a0ce764c4e9e0f

Contents?: true

Size: 680 Bytes

Versions: 38

Compression:

Stored size: 680 Bytes

Contents

# encoding: utf-8

module Kurchatov
  class Queue
    QUEUE_MAX_SIZE = 1_000
    QUEUE_MAX_FLUSH = 200

    def initialize
      @events = ::Queue.new
    end

    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

    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

  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
kurchatov-0.3.5 lib/kurchatov/queue.rb
kurchatov-0.3.4 lib/kurchatov/queue.rb
kurchatov-0.3.3 lib/kurchatov/queue.rb
kurchatov-0.3.2 lib/kurchatov/queue.rb
kurchatov-0.3.1 lib/kurchatov/queue.rb
kurchatov-0.3.0 lib/kurchatov/queue.rb
kurchatov-0.2.9 lib/kurchatov/queue.rb
kurchatov-0.2.8 lib/kurchatov/queue.rb
kurchatov-0.2.7 lib/kurchatov/queue.rb
kurchatov-0.2.6 lib/kurchatov/queue.rb
kurchatov-0.2.5 lib/kurchatov/queue.rb
kurchatov-0.2.4 lib/kurchatov/queue.rb
kurchatov-0.2.3 lib/kurchatov/queue.rb
kurchatov-0.2.2 lib/kurchatov/queue.rb
kurchatov-0.2.1 lib/kurchatov/queue.rb
kurchatov-0.2.0 lib/kurchatov/queue.rb
kurchatov-0.1.8 lib/kurchatov/queue.rb
kurchatov-0.1.7 lib/kurchatov/queue.rb
kurchatov-0.1.6 lib/kurchatov/queue.rb
kurchatov-0.1.5 lib/kurchatov/queue.rb