Sha256: e12f8f67d23475519832cd45a03d13ec70cbe3e14fed51a0217fa5063da6c3b9

Contents?: true

Size: 1.5 KB

Versions: 22

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  module Cache
    module Senders
      class MetricsSender
        def initialize(metrics_repository, api_key)
          @metrics_repository = metrics_repository
          @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
          SplitIoClient.configuration.threads[:metrics_sender] = Thread.new do
            begin
              SplitIoClient.configuration.logger.info('Starting metrics service')
              
              loop do
                post_metrics

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

              SplitIoClient.configuration.logger.info('Posting metrics due to shutdown')
            end
          end
        end

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

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

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
splitclient-rb-6.4.1-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.1 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.1.pre.rc3-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.1.pre.rc3 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.1.pre.rc2-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.1.pre.rc2 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.1.pre.rc1-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.1.pre.rc1 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.0-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.0 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.0.pre.rc1-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.4.0.pre.rc1 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.3.0-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.3.0 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.3.0.pre.rc1-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.3.0.pre.rc1 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.2.0-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.2.0 lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.2.0.pre.rc2-java lib/splitclient-rb/cache/senders/metrics_sender.rb
splitclient-rb-6.2.0.pre.rc2 lib/splitclient-rb/cache/senders/metrics_sender.rb