Sha256: 105ce77c7e73fc1985848ae28e1343679b2d29705802b42a5204cc0407290e9e

Contents?: true

Size: 1.18 KB

Versions: 29

Compression:

Stored size: 1.18 KB

Contents

module SplitIoClient
  module Cache
    module Senders
      class EventsSender
        def initialize(events_repository, config, api_key)
          @events_repository = events_repository
          @config = config
          @api_key = api_key
        end

        def call
          if ENV['SPLITCLIENT_ENV'] == 'test'
            post_events
          else
            events_thread

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

        private

        def events_thread
          @config.threads[:events_sender] = Thread.new do
            @config.logger.info('Starting events service')

            loop do
              post_events

              sleep(SplitIoClient::Utilities.randomize_interval(@config.events_push_rate))
            end
          end
        end

        def post_events
          SplitIoClient::Api::Events.new(@api_key, @config, @events_repository.clear).post
        rescue StandardError => error
          @config.log_found_exception(__method__.to_s, error)
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
splitclient-rb-5.1.0-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.0 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.0.pre.rc1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.0.pre.rc1 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.3-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.3 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.3.pre.rc1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.3.pre.rc1 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.2-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.2 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.2.pre.rc1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.2.pre.rc1 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.1 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.1.pre.rc1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.1.pre.rc1 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.0-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.0 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.0.pre.rc1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.0.0.pre.rc1 lib/splitclient-rb/cache/senders/events_sender.rb