Sha256: bee0b3088aa0be37803db68ea65caba49b3e98b7d2baceba4a4fae5ddfeecb16

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

require 'honeybadger/plugin'
require 'honeybadger/ruby'

module Honeybadger
  module Plugins
    module Resque
      module Extension
        def around_perform_with_honeybadger(*args)
          Honeybadger.flush do
            begin
              yield
            rescue Exception => e
              Honeybadger.notify(e, parameters: { job_arguments: args }) if send_exception?(e, args)
              raise e
            end
          end
        ensure
          Honeybadger.context.clear!
        end

        def send_exception?(e, args)
          return true unless respond_to?(:retry_criteria_valid?)
          return true if ::Honeybadger.config[:'resque.resque_retry.send_exceptions_when_retrying']

          !retry_criteria_valid?(e)
        rescue => e
          Honeybadger.notify(e, parameters: { job_arguments: args })
          raise e
        end
      end

      module Installer
        def self.included(base)
          base.send(:alias_method, :payload_class_without_honeybadger, :payload_class)
          base.send(:alias_method, :payload_class, :payload_class_with_honeybadger)
        end

        def payload_class_with_honeybadger
          payload_class_without_honeybadger.tap do |klass|
            unless klass.respond_to?(:around_perform_with_honeybadger)
              klass.instance_eval do
                extend(::Honeybadger::Plugins::Resque::Extension)
              end
            end
          end
        end
      end

      Plugin.register do
        requirement { defined?(::Resque::Job) }

        requirement do
          if resque_honeybadger = defined?(::Resque::Failure::Honeybadger)
            logger.warn("Support for Resque has been moved " \
                        "to the honeybadger gem. Please remove " \
                        "resque-honeybadger from your " \
                        "Gemfile.")
          end
          !resque_honeybadger
        end

        execution do
          ::Resque::Job.send(:include, Installer)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
honeybadger-3.0.0.beta5 lib/honeybadger/plugins/resque.rb
honeybadger-3.0.0.beta4 lib/honeybadger/plugins/resque.rb
honeybadger-3.0.0.beta3 lib/honeybadger/plugins/resque.rb
honeybadger-3.0.0.beta2 lib/honeybadger/plugins/resque.rb
honeybadger-3.0.0.beta1 lib/honeybadger/plugins/resque.rb