Sha256: 6f5dd98a66e2bb72ab6e5bfcc2ff96653898f3fafb443bbe5e250752c7fbac6a

Contents?: true

Size: 1.17 KB

Versions: 64

Compression:

Stored size: 1.17 KB

Contents

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

module Honeybadger
  module Plugins
    module Shoryuken
      class Middleware
        def call(_worker, _queue, sqs_msg, body)
          begin
            yield
          rescue => e
            if attempt_threshold <= receive_count(sqs_msg)
              Honeybadger.notify(e, parameters: notification_params(body))
            end

            raise e
          end
        ensure
          Honeybadger.clear!
        end

        private

        def attempt_threshold
          ::Honeybadger.config[:'shoryuken.attempt_threshold'].to_i
        end

        def receive_count(sqs_msg)
          return 0 if sqs_msg.is_a?(Array)

          sqs_msg.attributes['ApproximateReceiveCount'.freeze].to_i
        end

        def notification_params(body)
          body.is_a?(Array) ? { batch: body } : { body: body }
        end
      end

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

        execution do
          ::Shoryuken.configure_server do |config|
            config.server_middleware do |chain|
              chain.add Middleware
            end
          end
        end
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
honeybadger-5.0.0 lib/honeybadger/plugins/shoryuken.rb
honeybadger-5.0.0.beta1 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.12.2 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.12.1 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.12.0 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.11.0 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.10.0 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.9.0 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.8.0 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.7.3 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.7.2 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.7.1 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.7.0 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.6.0 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.5.6 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.5.5 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.5.4 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.5.3 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.5.2 lib/honeybadger/plugins/shoryuken.rb
honeybadger-4.5.1 lib/honeybadger/plugins/shoryuken.rb