class InfluxReporter::Worker

@api private

Attributes

config[R]

Public Class Methods

new(config, queue, influx_client) click to toggle source
# File lib/influx_reporter/worker.rb, line 17
def initialize(config, queue, influx_client)
  @config = config
  @queue = queue
  @influx_client = influx_client
end

Public Instance Methods

run() click to toggle source
# File lib/influx_reporter/worker.rb, line 25
def run
  loop do
    while action = @queue.pop
      case action
        when PostRequest
          process_request action
        when StopMessage
          Thread.exit
        else
          raise Error, "Unknown entity in worker queue: #{action.inspect}"
      end
    end
  end
end

Private Instance Methods

process_request(req) click to toggle source
# File lib/influx_reporter/worker.rb, line 42
def process_request(req)
  unless config.validate!
    info 'Invalid config - Skipping posting to influxdb'
    return
  end

  begin
    @influx_client.post(req.resource, req.data)
  rescue => e
    fatal "Failed POST: #{e.inspect}"
    debug e.backtrace.join("\n")
  end
end