Class: RailsPerformance::Models::RakeRecord

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRecord

#value

Constructor Details

#initialize(task:, duration: nil, datetime:, datetimei:, status:, json: '{}') ⇒ RakeRecord

Returns a new instance of RakeRecord.



20
21
22
23
24
25
26
27
28
29
# File 'lib/rails_performance/models/rake_record.rb', line 20

def initialize(task:, duration: nil, datetime:, datetimei:, status:, json: '{}')
  @task         = Array.wrap(task)
  @datetime     = datetime
  @datetimei    = datetimei.to_i
  @status       = status
  @duration     = duration
  @json         = json

  @duration ||= value['duration']
end

Instance Attribute Details

#datetimeObject

Returns the value of attribute datetime.



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

def datetime
  @datetime
end

#datetimeiObject

Returns the value of attribute datetimei.



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

def datetimei
  @datetimei
end

#durationObject

Returns the value of attribute duration.



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

def duration
  @duration
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#taskObject

Returns the value of attribute task.



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

def task
  @task
end

Class Method Details

.from_db(key, value) ⇒ Object

rake|task||datetime|20210416T1254|datetimei|1618602843|status|error|END|1.0.0 “duration”:0“duration”:0.00012442



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

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

  RakeRecord.new(
    task: JSON.parse(items[2]),
    datetime: items[4],
    datetimei: items[6],
    status: items[8],
    json: value
  )
end

Instance Method Details

#record_hashObject



31
32
33
34
35
36
37
38
39
# File 'lib/rails_performance/models/rake_record.rb', line 31

def record_hash
  {
    task: task,
    datetime: Time.at(datetimei),
    datetimei: datetimei,
    duration: duration,
    status: status,
  }
end

#saveObject



41
42
43
44
45
# File 'lib/rails_performance/models/rake_record.rb', line 41

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