Parent

Methods

Class/Module Index [+]

Quicksearch

Retriable::Retry

Attributes

interval[RW]
on[RW]
on_retry[RW]
timeout[RW]
tries[RW]

Public Class Methods

new() click to toggle source
# File lib/retriable/retry.rb, line 11
def initialize
  @tries      = 3
  @interval   = 0
  @timeout    = nil
  @on         = [StandardError, Timeout::Error]
  @on_retry   = nil

  yield self if block_given?
end

Public Instance Methods

perform() click to toggle source
# File lib/retriable/retry.rb, line 21
def perform
  count = 0
  begin
    if @timeout
      Timeout::timeout(@timeout) { yield }
    else
      yield
    end
  rescue *[*on] => exception
    @tries -= 1
    if @tries > 0
      count += 1
      @on_retry.call(exception, count) if @on_retry
      sleep_for = @interval.respond_to?(:call) ? @interval.call(count) : @interval
      sleep sleep_for if sleep_for > 0

      retry
    else
      raise
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.