Class: RailsPerformance::Models::SidekiqRecord

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRecord

#value

Constructor Details

#initialize(queue:, worker:, jid:, datetime:, datetimei:, enqueued_ati:, start_timei:, status: nil, duration: nil, json: "{}") ⇒ SidekiqRecord

Returns a new instance of SidekiqRecord.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rails_performance/models/sidekiq_record.rb', line 32

def initialize(queue:, worker:, jid:, datetime:, datetimei:, enqueued_ati:, start_timei:, status: nil, duration: nil, json: "{}")
  @queue        = queue
  @worker       = worker
  @jid          = jid
  @datetime     = datetime
  @datetimei    = datetimei.to_i
  @enqueued_ati = enqueued_ati
  @start_timei  = start_timei
  @status       = status
  @duration     = duration
  @json         = json
end

Instance Attribute Details

#datetimeObject

Returns the value of attribute datetime.



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

def datetime
  @datetime
end

#datetimeiObject

Returns the value of attribute datetimei.



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

def datetimei
  @datetimei
end

#durationObject

Returns the value of attribute duration.



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

def duration
  @duration
end

#enqueued_atiObject

Returns the value of attribute enqueued_ati.



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

def enqueued_ati
  @enqueued_ati
end

#jidObject

Returns the value of attribute jid.



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

def jid
  @jid
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#queueObject

Returns the value of attribute queue.



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

def queue
  @queue
end

#start_timeiObject

Returns the value of attribute start_timei.



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

def start_timei
  @start_timei
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#workerObject

Returns the value of attribute worker.



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

def worker
  @worker
end

Class Method Details

.from_db(key, value) ⇒ Object

key = job-performance |queue|default |worker|SimpleWorker |jid|7d48fbf20976c224510dbc60 |datetime|20200124T0523 |datetimei|1583146613 |enqueued_ati|1583146613 |start_timei|1583146614 |status|success|END|1.0.0 value = JSON



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails_performance/models/sidekiq_record.rb', line 16

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

  SidekiqRecord.new(
    queue: items[2],
    worker: items[4],
    jid: items[6],
    datetime: items[8],
    datetimei: items[10],
    enqueued_ati: items[12],
    start_timei: items[14],
    status: items[16],
    json: value
  )
end

Instance Method Details

#record_hashObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rails_performance/models/sidekiq_record.rb', line 45

def record_hash
  {
    worker: self.worker,
    queue: self.queue,
    jid: self.jid,
    status: self.status,
    datetimei: datetimei,
    datetime: Time.at(self.start_timei.to_i),
    duration: self.value['duration'],
    message: value['message']
  }
end

#saveObject



58
59
60
61
62
# File 'lib/rails_performance/models/sidekiq_record.rb', line 58

def save
  key   = "sidekiq|queue|#{queue}|worker|#{worker}|jid|#{jid}|datetime|#{datetime}|datetimei|#{datetimei}|enqueued_ati|#{enqueued_ati}|start_timei|#{start_timei}|status|#{status}|END|#{RailsPerformance::SCHEMA}"
  value = { message: message, duration: duration }
  Utils.save_to_redis(key, value)
end