Class: Octave::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/octave/payload.rb

Overview

A Payload contains information about each metric and the time to complete. After each Payload has been completed, it will be sent to each dispatcher.

To manually create a payload and send it to the dispatcher:

payload = Payload.new("name-of-event")
expensive_method
payload.done
Octave.dispatch(payload)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Payload

Creates a new Payload.

Parameters:

  • name (String)

    The name of the metric

  • options (Hash) (defaults to: {})

    Hash containing options. Useful for passing to dispatchers



17
18
19
20
21
# File 'lib/octave/payload.rb', line 17

def initialize(name, options = {})
  @start_time = Time.now
  @name       = name
  @options    = options
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



11
12
13
# File 'lib/octave/payload.rb', line 11

def end_time
  @end_time
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/octave/payload.rb', line 11

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/octave/payload.rb', line 11

def options
  @options
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



11
12
13
# File 'lib/octave/payload.rb', line 11

def start_time
  @start_time
end

Instance Method Details

#doneObject

Call this method immediately after the work has been completed.



24
25
26
# File 'lib/octave/payload.rb', line 24

def done
  @end_time = Time.now
end

#durationObject

Duration of the metric in milliseconds.



29
30
31
32
33
# File 'lib/octave/payload.rb', line 29

def duration
  return if end_time.nil?

  (end_time - start_time) * 1000.0
end