Sha256: 87fe3dabccda3be94b472e97e34a302e89034811cf883e4f82adfae7bac00b81

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require 'airbrake/sidekiq/retryable_jobs_filter'

module Airbrake
  module Sidekiq
    ##
    # Provides integration with Sidekiq v2+.
    class ErrorHandler
      # rubocop:disable Lint/RescueException
      def call(_worker, context, _queue)
        yield
      rescue Exception => exception
        notify_airbrake(exception, context)
        raise exception
      end
      # rubocop:enable Lint/RescueException

      private

      def notify_airbrake(exception, context)
        Airbrake.notify(exception, context) do |notice|
          notice[:context][:component] = 'sidekiq'
          notice[:context][:action] = action(context)
        end
      end

      ##
      # @return [String] job's name. When ActiveJob is present, retrieve
      #   job_class. When used directly, use worker's name
      def action(context)
        klass = context['class'] || context[:job] && context[:job]['class']
        return klass unless context[:job] && context[:job]['args'].first.is_a?(Hash)
        return klass unless (job_class = context[:job]['args'].first['job_class'])
        job_class
      end
    end
  end
end

if Sidekiq::VERSION < '3'
  Sidekiq.configure_server do |config|
    config.server_middleware do |chain|
      chain.add(Airbrake::Sidekiq::ErrorHandler)
    end
  end
else
  Sidekiq.configure_server do |config|
    config.error_handlers << Airbrake::Sidekiq::ErrorHandler.new.method(:notify_airbrake)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
airbrake-7.3.0 lib/airbrake/sidekiq.rb