Sha256: 1c4a2f9b6ae2c7763a6ec3e96ef49399ee76269f1d236da295f1a5e6e95a7f72

Contents?: true

Size: 1.15 KB

Versions: 11

Compression:

Stored size: 1.15 KB

Contents

require 'asir/transport/delegation'
require 'asir/retry_behavior'

module ASIR
  class Transport
    # !SLIDE
    # Retry Transport
    class Retry < self
      include Delegation, RetryBehavior

      # The transport to delegate to.
      attr_accessor :transport
      # Proc to call(transport, message) before retry.
      attr_accessor :before_retry

      def _send_message state
        first_exception = nil
        with_retry do | action, data |
          case action
          when :try
            result = transport.send_message(state.message)
            state.result = Result.new(state.message, result)
          when :rescue #, exc
            first_exception ||= data
            _handle_send_message_exception! transport, state, data
          when :retry #, exc
            before_retry.call(self, state) if before_retry
          when :failed
            @on_failed_message.call(self, state) if @on_failed_message
            if first_exception && @reraise_first_exception
              $! = first_exception
              raise
            end
            nil # fallback to raise RetryError
          end
        end
      end
    end
    # !SLIDE END
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
asir-1.2.11 lib/asir/transport/retry.rb
asir-1.2.10 lib/asir/transport/retry.rb
asir-1.2.9 lib/asir/transport/retry.rb
asir-1.2.8 lib/asir/transport/retry.rb
asir-1.2.7 lib/asir/transport/retry.rb
asir-1.2.6 lib/asir/transport/retry.rb
asir-1.2.5 lib/asir/transport/retry.rb
asir-1.2.3 lib/asir/transport/retry.rb
asir-1.2.2 lib/asir/transport/retry.rb
asir-1.2.1 lib/asir/transport/retry.rb
asir-1.2.0 lib/asir/transport/retry.rb