Sha256: c7a664c7d40f13412bca9074ef3831a28395d4777aeacf8602162fc877fd8a76

Contents?: true

Size: 1.64 KB

Versions: 22

Compression:

Stored size: 1.64 KB

Contents

module SplitIoClient
  module Cache
    module Senders
      class ImpressionsSender
        def initialize(impressions_repository, config, api_key)
          @impressions_repository = impressions_repository
          @config = config
          @api_key = api_key
        end

        def call
          # Disable impressions if @config.impressions_queue_size == -1
          if @config.impressions_queue_size < 0
            @config.logger.info('Disabling impressions service by config')
            return
          end

          if ENV['SPLITCLIENT_ENV'] == 'test'
            post_impressions
          else
            impressions_thread

            if defined?(PhusionPassenger)
              PhusionPassenger.on_event(:starting_worker_process) do |forked|
                impressions_thread if forked
              end
            end
          end
        end

        private

        def impressions_thread
          Thread.new do
            @config.logger.info('Starting impressions service')

            loop do
              post_impressions

              sleep(::Utilities.randomize_interval(@config.impressions_refresh_rate))
            end
          end
        end

        def post_impressions
          impressions_client.post
        rescue StandardError => error
          @config.log_found_exception(__method__.to_s, error)
        end

        def formatted_impressions(raw_impressions = nil)
          ImpressionsFormatter.new(@impressions_repository).call(raw_impressions)
        end

        def impressions_client
          SplitIoClient::Api::Impressions.new(@api_key, @config, formatted_impressions)
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
splitclient-rb-4.1.0 lib/cache/senders/impressions_sender.rb
splitclient-rb-4.1.0.pre.rc2 lib/cache/senders/impressions_sender.rb
splitclient-rb-4.1.0.pre.rc1 lib/cache/senders/impressions_sender.rb
splitclient-rb-4.0.0 lib/cache/senders/impressions_sender.rb
splitclient-rb-4.0.0.pre.rc1 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.3.0 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.3.0.pre.rc1 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.4 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.4.pre.rc5 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.4.pre.rc4 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.4.pre.rc3 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.4.pre.rc2 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.4.pre.rc1 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.3 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.3.pre.rc1 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.2 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.1 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.2.0 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.1.3 lib/cache/senders/impressions_sender.rb
splitclient-rb-3.1.3.pre.rc3 lib/cache/senders/impressions_sender.rb