Sha256: f468e69dca37e1ae6b0711b64842521bcf506a71098d7dc10641206d0d36919c

Contents?: true

Size: 1.21 KB

Versions: 16

Compression:

Stored size: 1.21 KB

Contents

module SplitIoClient
  module Cache
    module Senders
      class EventsSender
        def initialize(events_repository, api_key)
          @events_repository = events_repository
          @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
          SplitIoClient.configuration.threads[:events_sender] = Thread.new do
            SplitIoClient.configuration.logger.info('Starting events service')

            loop do
              post_events

              sleep(SplitIoClient::Utilities.randomize_interval(SplitIoClient.configuration.events_push_rate))
            end
          end
        end

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
splitclient-rb-5.1.4.pre.rc1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.4.pre.rc1 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.3.pre.rc1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.3.pre.rc1 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.2-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.2 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.2.pre.rc1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.2.pre.rc1 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.2.pre.rc21 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.2.pre.rc21-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.1 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.1.pre.rc2-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.1.pre.rc2 lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.1.pre.rc1-java lib/splitclient-rb/cache/senders/events_sender.rb
splitclient-rb-5.1.1.pre.rc1 lib/splitclient-rb/cache/senders/events_sender.rb