Sha256: 5356e617dec8494658b7466c7c03858cfe653a2e51ab238f9849ebe19822cc72

Contents?: true

Size: 1020 Bytes

Versions: 17

Compression:

Stored size: 1020 Bytes

Contents

module Sidekiq
  module Middleware
    module Server
      class Logging

        def call(worker, item, queue)
          Sidekiq::Logging.with_context(log_context(worker, item)) do
            begin
              start = Time.now
              logger.info("start".freeze)
              yield
              logger.info("done: #{elapsed(start)} sec")
            rescue Exception
              logger.info("fail: #{elapsed(start)} sec")
              raise
            end
          end
        end

        private

        # If we're using a wrapper class, like ActiveJob, use the "wrapped"
        # attribute to expose the underlying thing.
        def log_context(worker, item)
          klass = item['wrapped'.freeze] || worker.class.to_s
          "#{klass} JID-#{item['jid'.freeze]}#{" BID-#{item['bid'.freeze]}" if item['bid'.freeze]}"
        end

        def elapsed(start)
          (Time.now - start).round(3)
        end

        def logger
          Sidekiq.logger
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
sidekiq-4.2.9 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.2.8 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.2.7 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.2.6 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.2.5 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.2.4 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.2.3 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.2.2 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.2.1 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.2.0 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.1.4 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.1.3 lib/sidekiq/middleware/server/logging.rb
sr-sidekiq-4.1.6 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.1.2 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.1.1 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.1.0 lib/sidekiq/middleware/server/logging.rb
sidekiq-4.0.2 lib/sidekiq/middleware/server/logging.rb