class FFWD::EventEmitter

Used to emit events to an ‘output’ channel

Can take two parts of a configuration ‘base’ and ‘opts’ to decide which metadata emitted events should be decorated with.

Public Class Methods

build(output, base, opts) click to toggle source
# File lib/ffwd/event_emitter.rb, line 28
def self.build output, base, opts
  output = output
  host = opts[:host] || base[:host] || FFWD.current_host
  ttl = opts[:ttl] || base[:ttl]
  tags = FFWD.merge_sets base[:tags], opts[:tags]
  attributes = FFWD.merge_hashes base[:attributes], opts[:attributes]
  new output, host, ttl, tags, attributes
end
new(output, host, ttl, tags, attributes) click to toggle source
# File lib/ffwd/event_emitter.rb, line 37
def initialize output, host, ttl, tags, attributes
  @output = output
  @host = host
  @ttl = ttl
  @tags = tags
  @attributes = attributes
end

Public Instance Methods

emit(d) click to toggle source
# File lib/ffwd/event_emitter.rb, line 45
def emit d
  d[:time] ||= Time.now
  d[:host] ||= @host if @host
  d[:ttl] ||= @ttl if @ttl
  d[:value] = nil if (v = d[:value] and v.is_a?(Float) and v.nan?)
  d[:fixed_tags] = @tags
  d[:fixed_attr] = @attributes

  @output.event Event.make(d)
rescue => e
  log.error "Failed to emit event", e
end