Sha256: 778a2c30139868ce45060d0e21e787600f0194702f3a7dcff8e98d9edd2ce8e7

Contents?: true

Size: 1.45 KB

Versions: 13

Compression:

Stored size: 1.45 KB

Contents

require 'retriable'
require 'retriable/version'

module RunLoop
  # A class to bridge the gap between retriable 1.x and 2.0.
  class RetryOpts
    def self.tries_and_interval(tries, interval, other_retry_options={})
      retriable_version = RunLoop::Version.new(Retriable::VERSION)

      if other_retry_options[:tries]
        raise RuntimeError, ':tries is not a valid key for other_retry_options'
      elsif other_retry_options[:interval]
        raise RuntimeError, ':interval is not a valid key for other_retry_options'
      elsif other_retry_options[:intervals]
        raise RuntimeError, ':intervals is not a valid key for other_retry_options'
      end

      if retriable_version >= RunLoop::Version.new('2.0.0')
        other_retry_options.merge({:intervals => Array.new(tries, interval)})
      else
        other_retry_options.merge({:tries => tries, :interval => interval})
      end
    end
  end
end

# Only in retriable 1.4.0
unless Retriable.public_instance_methods.include?(:retriable)
  require 'retriable/retry'
  module Retriable
    extend self

    def retriable(opts = {}, &block)
      raise LocalJumpError unless block_given?

      Retry.new do |r|
        r.tries    = opts[:tries] if opts[:tries]
        r.on       = opts[:on] if opts[:on]
        r.interval = opts[:interval] if opts[:interval]
        r.timeout  = opts[:timeout] if opts[:timeout]
        r.on_retry = opts[:on_retry] if opts[:on_retry]
      end.perform(&block)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
run_loop-1.5.6 lib/run_loop/patches/retriable.rb
run_loop-1.5.6.pre1 lib/run_loop/patches/retriable.rb
run_loop-1.5.5 lib/run_loop/patches/retriable.rb
run_loop-1.5.4 lib/run_loop/patches/retriable.rb
run_loop-1.5.3 lib/run_loop/patches/retriable.rb
run_loop-1.5.2 lib/run_loop/patches/retriable.rb
run_loop-1.5.1 lib/run_loop/patches/retriable.rb
run_loop-1.5.0 lib/run_loop/patches/retriable.rb
run_loop-1.4.1 lib/run_loop/patches/retriable.rb
run_loop-1.4.0 lib/run_loop/patches/retriable.rb
run_loop-1.3.3 lib/run_loop/patches/retriable.rb
run_loop-1.3.3.pre1 lib/run_loop/patches/retriable.rb
run_loop-1.3.2 lib/run_loop/patches/retriable.rb