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.



68
69
70
71
# File 'lib/scout_apm/store.rb', line 68

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.



66
67
68
# File 'lib/scout_apm/store.rb', line 66

def timestamp
  @timestamp
end

Instance Method Details

#==(o) ⇒ Object



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

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

#age_in_secondsObject



89
90
91
# File 'lib/scout_apm/store.rb', line 89

def age_in_seconds
  Time.now.to_i - timestamp
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/scout_apm/store.rb', line 77

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

#hashObject



85
86
87
# File 'lib/scout_apm/store.rb', line 85

def hash
  timestamp.hash
end

#to_sObject



73
74
75
# File 'lib/scout_apm/store.rb', line 73

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