Sha256: 2996819cd91ae233ecb4f412ad854bc2d6be610363b79faa8e621aa70b65770e

Contents?: true

Size: 1.51 KB

Versions: 28

Compression:

Stored size: 1.51 KB

Contents

module SplitIoClient
  class ImpressionRouter
    attr_reader :router_thread

    def initialize(config)
      @config = config
      @listener = @config.impression_listener

      return unless @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)
      enqueue(impression)
    end

    def add_bulk(impressions)
      impressions[:split_names].each do |split_name|
        enqueue(
          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 enqueue(impression)
      @queue.push(impression) if @listener
    end

    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

28 entries across 28 versions & 1 rubygems

Version Path
splitclient-rb-7.0.2-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.2 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.2.pre.rc2-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.2.pre.rc2 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.2.pre.rc1-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.2.pre.rc1 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc7-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc7 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc6-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc6 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc5-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc5 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc4-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc4 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc3-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc3 lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc1-java lib/splitclient-rb/cache/routers/impression_router.rb
splitclient-rb-7.0.1.pre.rc1 lib/splitclient-rb/cache/routers/impression_router.rb