Sha256: e7c39d9aa1d4b4e28f94d9ec79d9e2267a6ef2f2dfded32cece1f8172ddfbed6

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

require 'sidekiq/job_logger'

module Loga
  module Sidekiq6
    class JobLogger < ::Sidekiq::JobLogger
      EVENT_TYPE = 'sidekiq'.freeze

      def call(item, _queue)
        start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)

        yield

        with_elapsed_time_context(start) do
          loga_log(
            message: "#{item['class']} with jid: '#{item['jid']}' done", item: item,
          )
        end
      rescue Exception => e # rubocop:disable Lint/RescueException
        with_elapsed_time_context(start) do
          loga_log(
            message: "#{item['class']} with jid: '#{item['jid']}' fail", item: item,
            exception: e
          )
        end

        raise
      end

      private

      def loga_log(message:, item:, exception: nil)
        data = {
          'created_at'  => item['created_at'],
          'enqueued_at' => item['enqueued_at'],
          'jid'         => item['jid'],
          'queue'       => item['queue'],
          'retry'       => item['retry'],
          'params'      => item['args'],
          'class'       => item['class'],
        }
        if exception
          data['exception'] = exception
          @logger.warn(Event.new(type: EVENT_TYPE, message: message, data: data))
        else
          @logger.info(Event.new(type: EVENT_TYPE, message: message, data: data))
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loga-2.6.0 lib/loga/sidekiq6/job_logger.rb
loga-2.5.4 lib/loga/sidekiq6/job_logger.rb
loga-2.5.3 lib/loga/sidekiq6/job_logger.rb