Sha256: 231f229c5e059c1ec3c9c2dc9f46004ddc977b70797618b1fea8acccbc1d449b

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

module Apress
  module Api
    module Callbacks
      class BaseCallback
        include Interactor

        def self.retry_exceptions
          @retry_exceptions ||= Set.new
        end

        def self.repeat_exceptions
          @repeat_exceptions ||= Set.new
        end

        def self.add_retry_exceptions(*errors)
          retry_exceptions.merge(errors)
        end

        def self.add_repeat_exceptions(*errors)
          repeat_exceptions.merge(errors)
          retry_exceptions.merge(errors)
        end

        def self.inherited(other)
          other.around do |interactor|
            begin
              interactor.call
            rescue Exception => error
              if self.class.repeat_exceptions.any? { |ex| ex === error }
                raise Apress::Api::Callbacks::RepeatCallbackError.new(error.message, error.backtrace)
              elsif self.class.retry_exceptions.any? { |ex| error.is_a?(Class) && ex >= error || ex === error }
                raise Apress::Api::Callbacks::FireCallbackError.new(error.message, error.backtrace)
              else
                raise error
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apress-api-1.24.0 app/interactors/apress/api/callbacks/base_callback.rb
apress-api-1.23.0 app/interactors/apress/api/callbacks/base_callback.rb
apress-api-1.22.1 app/interactors/apress/api/callbacks/base_callback.rb
apress-api-1.22.0 app/interactors/apress/api/callbacks/base_callback.rb