Sha256: e3f6ef87a58ee1ecf7f40a14edb153732d3097242c3744f78245b7c54bca7db6

Contents?: true

Size: 1.43 KB

Versions: 38

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  module Cache
    module Senders
      class MetricsSender
        def initialize(metrics_repository, api_key, config)
          @metrics_repository = metrics_repository
          @api_key = api_key
          @config = config
        end

        def call
          return if ENV['SPLITCLIENT_ENV'] == 'test'

          metrics_thread

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

        private

        def metrics_thread
          @config.threads[:metrics_sender] = Thread.new do
            begin
              @config.logger.info('Starting metrics service')

              loop do
                post_metrics

                sleep(SplitIoClient::Utilities.randomize_interval(@config.metrics_refresh_rate))
              end
            rescue SplitIoClient::SDKShutdownException
              post_metrics

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

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

        def metrics_api
          @metrics_api ||= SplitIoClient::Api::Metrics.new(@api_key, @metrics_repository, @config)
        end
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
splitclient-rb-7.0.3.pre.rc5-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.3.pre.rc5 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.3.pre.rc4-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.3.pre.rc4 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.3.pre.rc3-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.3.pre.rc3 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.3.pre.rc2-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.3.pre.rc2 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.3.pre.rc1-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.3.pre.rc1 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.2-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.2 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.2.pre.rc2-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.2.pre.rc2 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.2.pre.rc1-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.2.pre.rc1 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.1-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.1 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.1.pre.rc7-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-7.0.1.pre.rc7 lib/splitclient-rb/cache/senders/metrics_sender.rb