Sha256: 0df6095d4722c72a41addbcc36608292feb765a2dcd0b5b3b7e1128ec5f8a634

Contents?: true

Size: 830 Bytes

Versions: 8

Compression:

Stored size: 830 Bytes

Contents

require 'cassanity/retry_strategies/retry_strategy'

module Cassanity
  module RetryStrategies
    class RetryNTimes < RetryStrategy
      # Private
      attr_reader :retries

      # Public: initialize the retry strategy.
      #
      # args - The Hash of arguments.
      #        :retries - the number of times to retry an unsuccessful call
      #                   before failing.
      def initialize(args = {})
        # By default, there's no retries - if the call fails, you
        # get the error propagated to you.
        @retries = args[:retries] || 0
      end

      # Private: re-raise the exception from the last call if it's been retried
      # more than the maximum allowed amount.
      def fail(attempts, error)
        if attempts > @retries
          raise error
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cassanity-0.6.0 lib/cassanity/retry_strategies/retry_n_times.rb
cassanity-0.6.0.beta5 lib/cassanity/retry_strategies/retry_n_times.rb
cassanity-0.6.0.beta4 lib/cassanity/retry_strategies/retry_n_times.rb
cassanity-0.6.0.beta3 lib/cassanity/retry_strategies/retry_n_times.rb
cassanity-0.6.0.beta2 lib/cassanity/retry_strategies/retry_n_times.rb
cassanity-0.6.0.beta1 lib/cassanity/retry_strategies/retry_n_times.rb
cassanity-0.5.1 lib/cassanity/retry_strategies/retry_n_times.rb
cassanity-0.5.0 lib/cassanity/retry_strategies/retry_n_times.rb