Sha256: e10efcc53ad55f6a0029e48a8b396f460c1a617811b74104a51e9bc493d60f44

Contents?: true

Size: 1.54 KB

Versions: 58

Compression:

Stored size: 1.54 KB

Contents

module SplitIoClient
  class ImpressionRouter
    attr_reader :router_thread

    def initialize
      @listener = SplitIoClient.configuration.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
      SplitIoClient.configuration.threads[:impression_router] = Thread.new do
        loop do
          begin
            @listener.log(@queue.pop)
          rescue StandardError => error
            SplitIoClient.configuration.log_found_exception(__method__.to_s, error)
          end
        end
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

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