Sha256: 6b8682f8ef1119287551b7d597817796bd11ec74fd02d237b534c20b87baa9cc

Contents?: true

Size: 454 Bytes

Versions: 1

Compression:

Stored size: 454 Bytes

Contents

require "method_decorators"

module MethodDecorators
  class Retry < Decorator
    def initialize(max, options = {})
      @max = max
      @options = options
    end

    def call(orig, this, *args, &blk)
      attempts = 0
      begin
        attempts += 1
        orig.call(*args, &blk)
      rescue
        if attempts < @max
          sleep(@options[:sleep]) if @options[:sleep]
          retry
        end
        raise
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
method_decorators-0.9.5 lib/method_decorators/retry.rb