Class: Hallmonitor::TimedEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/hallmonitor/timed_event.rb

Overview

An event that represents a span of time

Instance Attribute Summary collapse

Attributes inherited from Event

#count, #name, #tags, #time

Instance Method Summary collapse

Methods included from Monitored

#emit, included, #watch

Constructor Details

#initialize(name, duration: nil, tags: {}) ⇒ TimedEvent

Parameters:

  • name (String)

    name of this event

  • duration (Number, Hash) (defaults to: nil)

    the timespan of this event, or multiple named timestamps



15
16
17
18
# File 'lib/hallmonitor/timed_event.rb', line 15

def initialize(name, duration: nil, tags: {})
  super(name, tags: tags)
  @duration = duration
end

Instance Attribute Details

#durationNumber

Reports duration of this timed event in ms

Returns:

  • (Number)

    duration, in ms if calculated based on #start and #stop



29
30
31
32
33
34
35
# File 'lib/hallmonitor/timed_event.rb', line 29

def duration
  if @duration
    @duration
  elsif @start && @stop
    (@stop - @start) * 1000
  end
end

#startDateTime

Returns the start time of this timed event.

Returns:

  • (DateTime)

    the start time of this timed event



9
10
11
# File 'lib/hallmonitor/timed_event.rb', line 9

def start
  @start
end

#stopDateTime

Returns the stop time of this timed event.

Returns:

  • (DateTime)

    the stop time of this timed event



9
# File 'lib/hallmonitor/timed_event.rb', line 9

attr_accessor :start, :stop

Instance Method Details

#to_json(*a) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/hallmonitor/timed_event.rb', line 37

def to_json(*a)
  {
    name: name,
    time: time,
    start: @start,
    stop:  @stop,
    duration: duration,
    tags: tags
  }.to_json(*a)
end