Class: RailsPerformance::Models::DelayedJobRecord

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRecord

#value

Constructor Details

#initialize(jid:, datetime:, datetimei:, source_type:, class_name:, method_name:, status:, duration: nil, json: "{}") ⇒ DelayedJobRecord

Returns a new instance of DelayedJobRecord.



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

def initialize(jid:, datetime:, datetimei:, source_type:, class_name:, method_name:, status:, duration: nil, json: "{}")
  @jid = jid
  @duration = duration
  @datetime = datetime
  @datetimei = datetimei.to_i
  @source_type = source_type
  @class_name = class_name
  @method_name = method_name
  @status = status
  @json = json
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



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

def class_name
  @class_name
end

#datetimeObject

Returns the value of attribute datetime.



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

def datetime
  @datetime
end

#datetimeiObject

Returns the value of attribute datetimei.



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

def datetimei
  @datetimei
end

#durationObject

Returns the value of attribute duration.



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

def duration
  @duration
end

#jidObject

Returns the value of attribute jid.



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

def jid
  @jid
end

#jsonObject

Returns the value of attribute json.



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

def json
  @json
end

#method_nameObject

Returns the value of attribute method_name.



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

def method_name
  @method_name
end

#source_typeObject

Returns the value of attribute source_type.



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

def source_type
  @source_type
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Class Method Details

.from_db(key, value) ⇒ Object

delayed_job |jid|22 |datetime|20210415T0616 |datetimei|1618492591 |source_type|instance_method |class_name|User |method_name|say_hello_without_delay |status|success|END|1.0.0



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

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

  DelayedJobRecord.new(
    jid: items[2],
    datetime: items[4],
    datetimei: items[6],
    source_type: items[8],
    class_name: items[10],
    method_name: items[12],
    status: items[14],
    json: value
  )
end

Instance Method Details

#record_hashObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rails_performance/models/delayed_job_record.rb', line 41

def record_hash
  {
    jid: jid,
    datetime: Time.at(datetimei),
    datetimei: datetimei,
    duration: value["duration"],
    status: status,
    source_type: source_type,
    class_name: class_name,
    method_name: method_name
  }
end

#saveObject



54
55
56
57
58
# File 'lib/rails_performance/models/delayed_job_record.rb', line 54

def save
  key = "delayed_job|jid|#{jid}|datetime|#{datetime}|datetimei|#{datetimei}|source_type|#{source_type}|class_name|#{class_name}|method_name|#{method_name}|status|#{status}|END|#{RailsPerformance::SCHEMA}"
  value = {duration: duration}
  Utils.save_to_redis(key, value)
end