Sha256: 7e72889f787b5fda05d7854a39ce7f9a6b860b01378f038d4561cf24d63a804d

Contents?: true

Size: 1.99 KB

Versions: 8

Compression:

Stored size: 1.99 KB

Contents

module ContextualizedLogs
  # https://github.com/mperham/sidekiq/wiki/Middleware
  module Sidekiq
    module Middleware
      module Server
        # https://github.com/mperham/sidekiq/wiki/Middleware
        class RestoreCurrentContext
          # @param [Object] worker the worker instance
          # @param [Hash] job the full job payload
          #   * @see https://github.com/mperham/sidekiq/wiki/Job-Format
          # @param [String] queue the name of the queue the job was pulled from
          # @yield the next middleware in the chain or worker `perform` method
          # @return [Void]
          def call(worker, job, queue)
            worker_klass = worker.class
            if worker_klass.include?(ContextualizedWorker)
              job_context_json = job['context']
              current_context = ContextualizedWorker.current_context
              current_context.from_json(job_context_json) if job_context_json
              current_context.current_job_id = job['jid']
              current_context.worker = worker.class.to_s
              # https://github.com/mperham/sidekiq/wiki/Job-Format
              current_context.worker_args = worker_klass.contextualize_args(job['args']) if worker_klass.respond_to?(:contextualize_args) && job['args']
              current_context.contextualize_model_enabled = worker_klass.contextualize_model_enabled
              if worker_klass.contextualize_worker_enabled
                Rails.logger.info "sidekiq: performing job #{worker_klass}: #{job['jid']}, on queue #{queue}"
                yield
                Rails.logger.info "sidekiq: completing job #{worker_klass}: #{job['jid']}, on queue #{queue}"
              end
            else
              yield
            end
          rescue StandardError => e
            if worker_klass.include?(ContextualizedWorker)
              Rails.logger.error "sidekiq: failure job #{worker.class}: #{job['jid']}, on queue #{queue}: #{e}"
            end
            raise e
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
contextualized_logs-0.0.8.pre.alpha lib/contextualized_logs/sidekiq/middleware/server/restore_current_context.rb
contextualized_logs-0.0.7.pre.alpha lib/contextualized_logs/sidekiq/middleware/server/restore_current_context.rb
contextualized_logs-0.0.6.pre.alpha lib/contextualized_logs/sidekiq/middleware/server/restore_current_context.rb
contextualized_logs-0.0.5.pre.alpha lib/contextualized_logs/sidekiq/middleware/server/restore_current_context.rb
contextualized_logs-0.0.4.pre.demo lib/contextualized_logs/sidekiq/middleware/server/restore_current_context.rb
contextualized_logs-0.0.4.pre.alpha lib/contextualized_logs/sidekiq/middleware/server/restore_current_context.rb
contextualized_logs-0.0.3.pre.alpha lib/contextualized_logs/sidekiq/middleware/server/restore_current_context.rb
contextualized_logs-0.0.2.pre.alpha lib/contextualized_logs/sidekiq/middleware/server/restore_current_context.rb