Sha256: cd114b1669df5df80d61c81c8c1f4af6e596eb16bd7f0933c3466be7ceedd8b2

Contents?: true

Size: 958 Bytes

Versions: 2

Compression:

Stored size: 958 Bytes

Contents

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

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

          post_metrics
          
          Thread.new do
            @config.logger.info('Starting metrics service')

            loop do
              post_metrics

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

        private

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

        def metrics_client
          SplitIoClient::Api::Metrics.new(@api_key, @config, @metrics_repository)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
splitclient-rb-3.1.3.pre.rc2 lib/cache/senders/metrics_sender.rb
splitclient-rb-3.1.3.pre.rc1 lib/cache/senders/metrics_sender.rb