Sha256: 1792aeb777f561bca0686083e0143d7923a5dddc7fc1514e10b6c87cce5eede5

Contents?: true

Size: 1002 Bytes

Versions: 2

Compression:

Stored size: 1002 Bytes

Contents

module Octave
  # 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)
  class Payload
    attr_reader :name, :options, :start_time, :end_time

    # Creates a new Payload.
    #
    # @param name [String] The name of the metric
    # @param options [Hash] Hash containing options. Useful for passing to dispatchers
    def initialize(name, options = {})
      @start_time = Time.now
      @name       = name
      @options    = options
    end

    # Call this method immediately after the work has been completed.
    def done
      @end_time = Time.now
    end

    # Duration of the metric in milliseconds.
    def duration
      return if end_time.nil?

      (end_time - start_time) * 1000.0
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
octave-0.1.1 lib/octave/payload.rb
octave-0.1.0 lib/octave/payload.rb