Sha256: d4cd8a1db284a6bfb440628be1bafd862a50d3fbfd85e4183378fdb5bdaffd3f

Contents?: true

Size: 1.41 KB

Versions: 22

Compression:

Stored size: 1.41 KB

Contents

module SplitIoClient
  class ImpressionRouter
    attr_reader :router_thread

    def initialize(config)
      @config = config
      @listener = config.impression_listener
      @queue = Queue.new
      router_thread

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

    def add(impression)
      @queue.push(impression)
    end

    def add_bulk(impressions)
      impressions[:split_names].each do |split_name|
        @queue.push(
          split_name: split_name.to_s,
          matching_key: impressions[:matching_key],
          bucketing_key: impressions[:bucketing_key],
          treatment: {
            label: impressions[:treatments_labels_change_numbers][split_name.to_sym][:label],
            treatment: impressions[:treatments_labels_change_numbers][split_name.to_sym][:treatment],
            change_number: impressions[:treatments_labels_change_numbers][split_name.to_sym][:change_number]
          },
          attributes: impressions[:attributes]
        )
      end
    end

    private

    def router_thread
      @config.threads[:impression_router] = Thread.new do
        loop do
          begin
            @listener.log(@queue.pop)
          rescue StandardError => error
            @config.log_found_exception(__method__.to_s, error)
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
splitclient-rb-5.0.1-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-5.0.1 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-5.0.1.pre.rc1-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-5.0.1.pre.rc1 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-5.0.0-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-5.0.0 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-5.0.0.pre.rc1-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-5.0.0.pre.rc1 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.5.2-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.5.2 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.5.2.pre.rc1-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.5.2.pre.rc1 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.5.1-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.5.1.pre.dev2 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.5.1.pre.dev lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.5.1 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.4.0 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.3.2 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.3.1 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-4.3.0 lib/splitclient-rb/cache/routers/impression_router.rb