Sha256: dc998464a7ddd240d27dff4717622c623b6fd1c1add0576ee9885273d30a1174

Contents?: true

Size: 1.19 KB

Versions: 42

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  module Cache
    module Repositories
      module Impressions
        class MemoryRepository < ImpressionsRepository
          def initialize(config)
            @config = config
            @adapter = @config.impressions_adapter
          end

          def add_bulk(impressions)
            impressions.each do |impression|
              @adapter.add_to_queue(impression)
            end
          rescue ThreadError # queue is full
            if random_sampler.rand(1..1000) <= 2 # log only 0.2 % of the time
              @config.logger.warn("Dropping impressions. Current size is \
                #{@config.impressions_queue_size}. " \
                'Consider increasing impressions_queue_size')
            end
          end

          def batch
            return [] if @config.impressions_bulk_size.zero?

            @adapter.get_batch(@config.impressions_bulk_size)
          end

          def clear
            @adapter.clear
          end

          def empty?
            @adapter.empty?
          end

          private

          def random_sampler
            @random_sampler ||= Random.new
          end
        end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
splitclient-rb-7.2.3-java lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.3 lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.3.pre.rc2-java lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.3.pre.rc2 lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.3.pre.rc1-java lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.3.pre.rc1 lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.2-java lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.2 lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.2.pre.rc1-java lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.2.pre.rc1 lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.1-java lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.1 lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.1.pre.rc1-java lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.1.pre.rc1 lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.0.pre.rc1-java lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.0.pre.rc1 lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.0-java lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.2.0 lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.1.4.pre.rc19-java lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb
splitclient-rb-7.1.4.pre.rc19 lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb