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.1.4 lib/kurchatov/queue.rb
kurchatov-0.1.3 lib/kurchatov/queue.rb
kurchatov-0.1.2 lib/kurchatov/queue.rb
kurchatov-0.1.1 lib/kurchatov/queue.rb
kurchatov-0.1.0 lib/kurchatov/queue.rb
kurchatov-0.0.9 lib/kurchatov/queue.rb
kurchatov-0.0.8.pre.3 lib/kurchatov/queue.rb
kurchatov-0.0.7.pre.4 lib/kurchatov/queue.rb
kurchatov-0.0.8.pre.2 lib/kurchatov/queue.rb
kurchatov-0.0.8.pre.1 lib/kurchatov/queue.rb
kurchatov-0.0.7 lib/kurchatov/queue.rb
kurchatov-0.0.7.pre.3 lib/kurchatov/queue.rb
kurchatov-0.0.7.pre.2 lib/kurchatov/queue.rb
kurchatov-0.0.7.pre.1 lib/kurchatov/queue.rb
kurchatov-0.0.6 lib/kurchatov/queue.rb
kurchatov-0.0.6.pre.5 lib/kurchatov/queue.rb
kurchatov-0.0.6.pre.4 lib/kurchatov/queue.rb
kurchatov-0.0.6.pre.3 lib/kurchatov/queue.rb