Sha256: 0d36958429398a920052f8949f18c2349b1b82cf5d31ab8e4763d2efea9c7b28

Contents?: true

Size: 1.84 KB

Versions: 72

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  module SSE
    module Workers
      class SplitsWorker
        def initialize(synchronizer, config, splits_repository)
          @synchronizer = synchronizer
          @config = config
          @splits_repository = splits_repository
        end

        def start
          return if SplitIoClient::Helpers::ThreadHelper.alive?(:split_update_worker, @config)

          @queue = Queue.new
          perform_thread
        end

        def add_to_queue(change_number)
          return if @queue.nil?

          @config.logger.debug("SplitsWorker add to queue #{change_number}")
          @queue.push(change_number)
        end

        def kill_split(change_number, split_name, default_treatment)
          return if @queue.nil?

          @config.logger.debug("SplitsWorker kill #{split_name}, #{change_number}")
          @splits_repository.kill(change_number, split_name, default_treatment)
          add_to_queue(change_number)
        end

        def stop
          SplitIoClient::Helpers::ThreadHelper.stop(:split_update_worker, @config)
          @queue = nil
        end

        private

        def perform
          while (change_number = @queue.pop)
            since = @splits_repository.get_change_number

            unless since.to_i >= change_number
              @config.logger.debug("SplitsWorker fetch_splits with #{since}")
              @synchronizer.fetch_splits
            end
          end
        end

        def perform_thread
          @config.threads[:split_update_worker] = Thread.new do
            @config.logger.debug('Starting splits worker ...') if @config.debug_enabled
            perform
          end
        end

        def perform_passenger_forked
          PhusionPassenger.on_event(:starting_worker_process) { |forked| perform_thread if forked }
        end
      end
    end
  end
end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
splitclient-rb-7.2.0-java lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.2.0 lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc19-java lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc19 lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc18-java lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc18 lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc17-java lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc17 lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc16-java lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc16 lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc15-java lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc15 lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc14-java lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc14 lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc13-java lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc13 lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc12-java lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc12 lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc11-java lib/splitclient-rb/sse/workers/splits_worker.rb
splitclient-rb-7.1.4.pre.rc11 lib/splitclient-rb/sse/workers/splits_worker.rb