Sha256: 5732f7228d499638d403b13087ef22a87287cf5a01e377f1289ce42fe0731a86

Contents?: true

Size: 860 Bytes

Versions: 9

Compression:

Stored size: 860 Bytes

Contents

# frozen_string_literal: true

module ElasticAPM
  # @api private
  class Worker
    include Log

    # @api private
    class StopMessage; end

    # @api private
    Request = Struct.new(:path, :payload) do
      # require all params
      def initialize(path, payload)
        super
      end
    end

    def initialize(config, queue, adapter)
      @config = config
      @adapter = adapter
      @queue = queue
    end

    def run_forever
      loop do
        while (item = @queue.pop)
          case item
          when Request
            process item
          when StopMessage
            Thread.exit
          end
        end
      end
    end

    def process(item)
      @adapter.post(item.path, item.payload)
    rescue ::Exception => e
      fatal 'Failed posting: %s', e.inspect
      debug e.backtrace.join("\n")
      nil
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
elastic-apm-0.5.1 lib/elastic_apm/worker.rb
elastic-apm-0.5.0 lib/elastic_apm/worker.rb
elastic-apm-0.4.5 lib/elastic_apm/worker.rb
elastic-apm-0.4.4 lib/elastic_apm/worker.rb
elastic-apm-0.4.3 lib/elastic_apm/worker.rb
elastic-apm-0.4.2 lib/elastic_apm/worker.rb
elastic-apm-0.4.1 lib/elastic_apm/worker.rb
elastic-apm-0.4.0 lib/elastic_apm/worker.rb
elastic-apm-0.3.0 lib/elastic_apm/worker.rb