class Sidekiq::JobMonitor::Job
Attributes
attributes[R]
original_job[R]
Public Class Methods
find(jid)
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 66 def find(jid) find_in_queues(jid) || find_in_previous(jid) end
new(attributes)
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 6 def initialize(attributes) @attributes = attributes.as_json(only: %w(class jid args state)) @original_job = attributes[:original_job] end
store_key_for(jid)
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 70 def store_key_for(jid) ['sidekiq-job_monitor', jid].join(':') end
Private Class Methods
find_in_previous(jid)
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 84 def find_in_previous(jid) data = Sidekiq.redis do |conn| conn.get(store_key_for(jid)) end new(JSON.parse(data)) if data end
find_in_queues(jid)
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 76 def find_in_queues(jid) job = Sidekiq::Queue.new.find_job(jid) return unless job attributes = { original_job: job }.merge(job.item) new(attributes) end
Public Instance Methods
as_json(*args)
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 43 def as_json(*args) attributes.as_json(*args) end
cancel()
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 60 def cancel return unless original_job original_job.delete end
monitoring_data()
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 51 def monitoring_data worker_instance = worker.new worker_instance.jid = attributes['jid'] if worker_instance.respond_to?(:monitoring_data) worker_instance.monitoring_data(*attributes['args'], state) end end
save()
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 11 def save Sidekiq.redis do |conn| conn.set(store_key, serialize) # Expire key in 1 hours to avoid garbage keys conn.expire(store_key, 3_600) if conn.ttl(store_key) == -1 end end
serialize()
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 23 def serialize attributes.to_json end
state()
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 27 def state @state ||= attributes['state'] || 'pending' end
state=(value)
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 39 def state=(value) @state = attributes['state'] = value end
store_key()
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 19 def store_key @store_key ||= self.class.store_key_for(attributes['jid']) end
worker()
click to toggle source
# File lib/sidekiq/job_monitor/job.rb, line 47 def worker attributes['class'].constantize end