Class: RailsPerformance::Models::CustomRecord

Inherits:
BaseRecord
  • Object
show all
Defined in:
lib/rails_performance/models/custom_record.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRecord

#value

Constructor Details

#initialize(tag_name:, datetime:, datetimei:, status:, namespace_name: nil, duration: nil, json: "{}") ⇒ CustomRecord

Returns a new instance of CustomRecord.



19
20
21
22
23
24
25
26
27
# File 'lib/rails_performance/models/custom_record.rb', line 19

def initialize(tag_name:, datetime:, datetimei:, status:, namespace_name: nil, duration: nil, json: "{}")
  @tag_name = tag_name
  @namespace_name = namespace_name
  @duration = duration
  @datetime = datetime
  @datetimei = datetimei.to_i
  @status = status
  @json = json
end

Instance Attribute Details

#datetimeObject

Returns the value of attribute datetime.



4
5
6
# File 'lib/rails_performance/models/custom_record.rb', line 4

def datetime
  @datetime
end

#datetimeiObject

Returns the value of attribute datetimei.



4
5
6
# File 'lib/rails_performance/models/custom_record.rb', line 4

def datetimei
  @datetimei
end

#durationObject

Returns the value of attribute duration.



4
5
6
# File 'lib/rails_performance/models/custom_record.rb', line 4

def duration
  @duration
end

#jsonObject

Returns the value of attribute json.



4
5
6
# File 'lib/rails_performance/models/custom_record.rb', line 4

def json
  @json
end

#namespace_nameObject

Returns the value of attribute namespace_name.



4
5
6
# File 'lib/rails_performance/models/custom_record.rb', line 4

def namespace_name
  @namespace_name
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/rails_performance/models/custom_record.rb', line 4

def status
  @status
end

#tag_nameObject

Returns the value of attribute tag_name.



4
5
6
# File 'lib/rails_performance/models/custom_record.rb', line 4

def tag_name
  @tag_name
end

Class Method Details

.from_db(key, value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rails_performance/models/custom_record.rb', line 6

def self.from_db(key, value)
  items = key.split("|")

  CustomRecord.new(
    tag_name: items[2],
    namespace_name: items[4],
    datetime: items[6],
    datetimei: items[8],
    status: items[10],
    json: value
  )
end

Instance Method Details

#record_hashObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/rails_performance/models/custom_record.rb', line 29

def record_hash
  {
    tag_name: tag_name,
    namespace_name: namespace_name,
    status: status,
    datetimei: datetimei,
    datetime: Time.at(datetimei.to_i),
    duration: value["duration"]
  }
end

#saveObject



40
41
42
43
44
# File 'lib/rails_performance/models/custom_record.rb', line 40

def save
  key = "custom|tag_name|#{tag_name}|namespace_name|#{namespace_name}|datetime|#{datetime}|datetimei|#{datetimei}|status|#{status}|END|#{RailsPerformance::SCHEMA}"
  value = {duration: duration}
  Utils.save_to_redis(key, value)
end