Sha256: 2fb1b2ac7c86f3586452a0739689b69bb5ff9a6dd0e88e2ad5ea9ecd5ff616aa

Contents?: true

Size: 1.38 KB

Versions: 62

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

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

        def call
          impressions_thread
        end

        private

        def impressions_thread
          @config.threads[:impressions_sender] = Thread.new do
            begin
              @config.logger.info('Starting impressions service')

              loop do
                post_impressions(false)

                sleep(SplitIoClient::Utilities.randomize_interval(@config.impressions_refresh_rate))
              end
            rescue SplitIoClient::SDKShutdownException
              post_impressions

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

        def post_impressions(fetch_all_impressions = true)
          formatted_impressions = ImpressionsFormatter.new(@impressions_repository)
            .call(fetch_all_impressions)

          impressions_api.post(formatted_impressions)
        rescue StandardError => e
          @config.log_found_exception(__method__.to_s, e)
        end

        def impressions_api
          @impressions_api
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
splitclient-rb-8.1.2.pre.rc1-java lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.2.pre.rc1 lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.1-java lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.1 lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.1.pre.rc3-java lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.1.pre.rc3 lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.1.pre.rc2-java lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.1.pre.rc2 lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.1.pre.rc1-java lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.1.pre.rc1 lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.0-java lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.0 lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.0.pre.rc1-java lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.1.0.pre.rc1 lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.0.1-java lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.0.1 lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.0.1.pre.rc1-java lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.0.1.pre.rc1 lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.0.0-java lib/splitclient-rb/cache/senders/impressions_sender.rb
splitclient-rb-8.0.0 lib/splitclient-rb/cache/senders/impressions_sender.rb