Class: RailsPerformance::Models::ResourceRecord

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRecord

#duration, #value

Constructor Details

#initialize(server:, context:, role:, datetime:, datetimei:, json:) ⇒ ResourceRecord

Returns a new instance of ResourceRecord.



6
7
8
9
10
11
12
13
# File 'lib/rails_performance/models/resource_record.rb', line 6

def initialize(server:, context:, role:, datetime:, datetimei:, json:)
  @server = server
  @context = context
  @role = role
  @datetime = datetime
  @datetimei = datetimei
  @json = json
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



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

def context
  @context
end

#datetimeObject

Returns the value of attribute datetime.



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

def datetime
  @datetime
end

#datetimeiObject

Returns the value of attribute datetimei.



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

def datetimei
  @datetimei
end

#jsonObject

Returns the value of attribute json.



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

def json
  @json
end

#roleObject

Returns the value of attribute role.



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

def role
  @role
end

#serverObject

Returns the value of attribute server.



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

def server
  @server
end

Class Method Details

.from_db(key, value) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rails_performance/models/resource_record.rb', line 15

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

  ResourceRecord.new(
    server: items[2],
    context: items[4],
    role: items[6],
    datetime: items[8],
    datetimei: items[10],
    json: value
  )
end

Instance Method Details

#record_hashObject



28
29
30
31
32
33
34
35
36
# File 'lib/rails_performance/models/resource_record.rb', line 28

def record_hash
  value.symbolize_keys.merge({
    server: server,
    role: role,
    context: context,
    datetime: datetime,
    datetimei: RailsPerformance::Utils.from_datetimei(datetimei.to_i)
  })
end

#saveObject



38
39
40
41
42
# File 'lib/rails_performance/models/resource_record.rb', line 38

def save
  key = "resource|server|#{server}|context|#{context}|role|#{role}|datetime|#{datetime}|datetimei|#{datetimei}|END|#{RailsPerformance::SCHEMA}"
  # with longer expiration time
  Utils.save_to_redis(key, json, RailsPerformance.system_monitor_duration.to_i)
end