Sha256: 83428a59052ac28d8f256e5dc02c74eda808080134e637ba166a69b1a1957d24

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

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

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

              raise e
            end
          end
        ensure
          Honeybadger.context.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

7 entries across 7 versions & 1 rubygems

Version Path
honeybadger-3.4.0.beta1 lib/honeybadger/plugins/shoryuken.rb
honeybadger-3.3.0 lib/honeybadger/plugins/shoryuken.rb
honeybadger-3.2.0 lib/honeybadger/plugins/shoryuken.rb
honeybadger-3.2.0.beta1 lib/honeybadger/plugins/shoryuken.rb
honeybadger-3.1.2 lib/honeybadger/plugins/shoryuken.rb
honeybadger-3.1.1 lib/honeybadger/plugins/shoryuken.rb
honeybadger-3.1.0 lib/honeybadger/plugins/shoryuken.rb