Sha256: 77b9763489be2e168006a62f5755967535b6ef2a08d1611d63aa4b9e69bfb516

Contents?: true

Size: 1.56 KB

Versions: 52

Compression:

Stored size: 1.56 KB

Contents

module Puppet::Util::RetryAction
  class RetryException < Exception; end
  class RetryException::NoBlockGiven < RetryException; end
  class RetryException::NoRetriesGiven < RetryException;end
  class RetryException::RetriesExceeded < RetryException; end

  def self.retry_action( parameters = { :retry_exceptions => nil, :retries => nil } )
    # Retry actions for a specified amount of time. This method will allow the final
    # retry to complete even if that extends beyond the timeout period.
    unless block_given?
      raise RetryException::NoBlockGiven
    end

    raise RetryException::NoRetriesGiven if parameters[:retries].nil?
    parameters[:retry_exceptions] ||= Hash.new

    start = Time.now
    failures = 0

    begin
      yield
    rescue Exception => e
      # If we were giving exceptions to catch,
      # catch the excptions we care about and retry.
      # All others fail hard

      raise RetryException::RetriesExceeded if parameters[:retries] == 0

      if (not parameters[:retry_exceptions].keys.empty?) and parameters[:retry_exceptions].keys.include?(e.class)
        Puppet.info("Caught exception #{e.class}:#{e}")
        Puppet.info(parameters[:retry_exceptions][e.class])
      elsif (not parameters[:retry_exceptions].keys.empty?)
        # If the exceptions is not in the list of retry_exceptions re-raise.
        raise e
      end

      failures += 1
      parameters[:retries] -= 1

      # Increase the amount of time that we sleep after every
      # failed retry attempt.
      sleep (((2 ** failures) -1) * 0.1)

      retry

    end
  end
end

Version data entries

52 entries across 52 versions & 3 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/util/retryaction.rb
puppet-parse-0.1.3 lib/vendor/puppet/util/retryaction.rb
puppet-parse-0.1.2 lib/vendor/puppet/util/retryaction.rb
puppet-parse-0.1.1 lib/vendor/puppet/util/retryaction.rb
puppet-2.7.26 lib/puppet/util/retryaction.rb
puppet-2.7.25 lib/puppet/util/retryaction.rb
puppet-2.7.24 lib/puppet/util/retryaction.rb
puppet-3.2.4 lib/puppet/util/retryaction.rb
puppet-2.7.23 lib/puppet/util/retryaction.rb
puppet-3.2.3 lib/puppet/util/retryaction.rb
puppet-3.2.3.rc1 lib/puppet/util/retryaction.rb
puppet-3.2.2 lib/puppet/util/retryaction.rb
puppet-2.7.22 lib/puppet/util/retryaction.rb
puppet-3.2.1 lib/puppet/util/retryaction.rb
puppet-3.2.1.rc1 lib/puppet/util/retryaction.rb
puppet-3.2.0.rc2 lib/puppet/util/retryaction.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/lib/puppet/util/retryaction.rb
puppet-3.2.0.rc1 lib/puppet/util/retryaction.rb
puppet-parse-0.1.0 lib/vendor/puppet/util/retryaction.rb
puppet-parse-0.0.6 lib/vendor/puppet/util/retryaction.rb