Sha256: ca0591bbde8362e28200794930c640061e9ab74106ce035f06f4fbdfe438f867

Contents?: true

Size: 1.25 KB

Versions: 8

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  module Cache
    module Senders
      class ImpressionsCountSender
        def initialize(config, impression_counter, impressions_sender_adapter)
          @config = config
          @impression_counter = impression_counter
          @impressions_sender_adapter = impressions_sender_adapter
        end

        def call
          impressions_count_thread
        end

        private

        def impressions_count_thread
          @config.threads[:impressions_count_sender] = Thread.new do
            begin
              @config.logger.info('Starting impressions count service')
              loop do
                sleep(@config.counter_refresh_rate)
                post_impressions_count                
              end
            rescue SplitIoClient::SDKShutdownException              
              post_impressions_count

              @config.logger.info('Posting impressions count due to shutdown')
            end
          end
        end

        def post_impressions_count
          @impressions_sender_adapter.record_impressions_count(@impression_counter.pop_all)
        rescue StandardError => error
          @config.log_found_exception(__method__.to_s, error)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
splitclient-rb-7.3.5.pre.rc4-java lib/splitclient-rb/cache/senders/impressions_count_sender.rb
splitclient-rb-7.3.5.pre.rc4 lib/splitclient-rb/cache/senders/impressions_count_sender.rb
splitclient-rb-7.3.5.pre.rc3-java lib/splitclient-rb/cache/senders/impressions_count_sender.rb
splitclient-rb-7.3.5.pre.rc3 lib/splitclient-rb/cache/senders/impressions_count_sender.rb
splitclient-rb-7.3.5.pre.rc2-java lib/splitclient-rb/cache/senders/impressions_count_sender.rb
splitclient-rb-7.3.5.pre.rc2 lib/splitclient-rb/cache/senders/impressions_count_sender.rb
splitclient-rb-7.3.5.pre.rc1-java lib/splitclient-rb/cache/senders/impressions_count_sender.rb
splitclient-rb-7.3.5.pre.rc1 lib/splitclient-rb/cache/senders/impressions_count_sender.rb