class Ezlog::Sidekiq::JobContext

Public Class Methods

from_job_hash(job_hash) click to toggle source
# File lib/ezlog/sidekiq/job_context.rb, line 5
def from_job_hash(job_hash)
  return {} if job_hash.nil?
  thread_info.merge(basic_info_from(job_hash)).merge(named_arguments_from(job_hash))
end

Private Class Methods

basic_info_from(job) click to toggle source
# File lib/ezlog/sidekiq/job_context.rb, line 17
def basic_info_from(job)
  h = {
    jid: job['jid'],
    queue: job['queue'],
    worker: job_class(job),
    created_at: job['created_at'],
    enqueued_at: job['enqueued_at'],
    run_count: (job['retry_count'] || -1) + 2
  }
  h[:bid] = job['bid'] if job['bid']
  h[:tags] = job['tags'] if job['tags']
  h
end
job_class(job) click to toggle source
# File lib/ezlog/sidekiq/job_context.rb, line 43
def job_class(job)
  job['wrapped'] || job['class']
end
method_parameters_of(job) click to toggle source
# File lib/ezlog/sidekiq/job_context.rb, line 39
def method_parameters_of(job)
  Kernel.const_get(job_class(job)).instance_method(:perform).parameters
end
named_arguments_from(job) click to toggle source
# File lib/ezlog/sidekiq/job_context.rb, line 31
def named_arguments_from(job)
  {}.tap do |arguments|
    method_parameters_of(job).each_with_index do |(_, param_name), index|
      arguments[param_name] = job['args'][index]
    end
  end
end
thread_info() click to toggle source
# File lib/ezlog/sidekiq/job_context.rb, line 12
def thread_info
  { tid: Thread.current['sidekiq_tid'] || (Thread.current.object_id ^ ::Process.pid).to_s(36) }
end