Sha256: 1e9066ef3039f9c43128778bb9d0ab9dc61b794582b02b86d43d1912fceb47ac
Contents?: true
Size: 1.54 KB
Versions: 4
Compression:
Stored size: 1.54 KB
Contents
# frozen_string_literal: true module Sidekiq class JobLogger def initialize(config) @config = config @logger = @config.logger end # If true we won't do any job logging out of the box. # The user is responsible for any logging. def skip_default_logging? @config[:skip_default_job_logging] end def call(item, queue) return yield if skip_default_logging? begin start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) @logger.info("start") yield Sidekiq::Context.add(:elapsed, elapsed(start)) @logger.info("done") rescue Exception Sidekiq::Context.add(:elapsed, elapsed(start)) @logger.info("fail") raise end end def prepare(job_hash, &block) # If we're using a wrapper class, like ActiveJob, use the "wrapped" # attribute to expose the underlying thing. h = { class: job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"], jid: job_hash["jid"] } h[:bid] = job_hash["bid"] if job_hash.has_key?("bid") h[:tags] = job_hash["tags"] if job_hash.has_key?("tags") Thread.current[:sidekiq_context] = h level = job_hash["log_level"] if level && @logger.respond_to?(:log_at) @logger.log_at(level, &block) else yield end ensure Thread.current[:sidekiq_context] = nil end private def elapsed(start) (::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start).round(3) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-7.3.4 | lib/sidekiq/job_logger.rb |
sidekiq-7.3.3 | lib/sidekiq/job_logger.rb |
sidekiq-7.3.2 | lib/sidekiq/job_logger.rb |
sidekiq-7.3.1 | lib/sidekiq/job_logger.rb |