Sha256: 8b78c916ab56b4a5d3b3cee2ad80b2714e95f134ac9fc4d9a2aac99de1be0c4f

Contents?: true

Size: 846 Bytes

Versions: 1

Compression:

Stored size: 846 Bytes

Contents

module Heavylog
  class SidekiqLogger
    def call(item, queue)
      # item = {"class"=>"SuspiciousJob", "args"=>[12754545, [3858890], "invoice"], "retry"=>true, "queue"=>"default", "jid"=>"5ec968571e358497d70a3cf2", "created_at"=>1540484817.3950138, "enqueued_at"=>1540484817.395076}

      Heavylog.log_sidekiq(item["jid"], item["class"], item["args"])

      begin
        start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
        logger.info("start")
        yield
        logger.info("done: #{elapsed(start)} sec")
        Heavylog.finish_sidekiq
      rescue Exception
        logger.info("fail: #{elapsed(start)} sec")
        raise
      end
    end

    private

    def elapsed(start)
      (::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start).round(3)
    end

    def logger
      Sidekiq.logger
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heavylog-0.0.9 lib/heavylog/sidekiq_logger.rb