Sha256: 64274b4e920c47c4290161f0b377fbf605c7dfafccda2786b652cb08f8c0b3a8

Contents?: true

Size: 1.15 KB

Versions: 20

Compression:

Stored size: 1.15 KB

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'

          metrics_thread

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

        private

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

            loop do
              post_metrics

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

        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

20 entries across 20 versions & 1 rubygems

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