Class: ScoutApm::StoreReportingPeriodTimestamp

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/store.rb

Overview

A timestamp, normalized to the beginning of a minute. Used as a hash key to bucket metrics into per-minute groups

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = Time.now) ⇒ StoreReportingPeriodTimestamp

Returns a new instance of StoreReportingPeriodTimestamp.



82
83
84
85
# File 'lib/scout_apm/store.rb', line 82

def initialize(time=Time.now)
  @raw_time = time.utc # The actual time passed in. Store it so we can to_s it without reparsing a timestamp
  @timestamp = @raw_time.to_i - @raw_time.sec # The normalized time (integer) to compare by
end

Instance Attribute Details

#timestampObject (readonly)

Returns the value of attribute timestamp.



80
81
82
# File 'lib/scout_apm/store.rb', line 80

def timestamp
  @timestamp
end

Instance Method Details

#==(o) ⇒ Object



95
96
97
# File 'lib/scout_apm/store.rb', line 95

def ==(o)
  self.eql?(o)
end

#age_in_secondsObject



103
104
105
# File 'lib/scout_apm/store.rb', line 103

def age_in_seconds
  Time.now.to_i - timestamp
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/scout_apm/store.rb', line 91

def eql?(o)
  self.class == o.class && timestamp.eql?(o.timestamp)
end

#hashObject



99
100
101
# File 'lib/scout_apm/store.rb', line 99

def hash
  timestamp.hash
end

#to_sObject



87
88
89
# File 'lib/scout_apm/store.rb', line 87

def to_s
  Time.at(@timestamp).iso8601
end