module Retry

Constants

DEFAULT_MAX_NO_OF_RETRIES
DEFAULT_RESCUE_ERRORS

Public Class Methods

call(no_of_retries: DEFAULT_MAX_NO_OF_RETRIES, rescue_errors: DEFAULT_RESCUE_ERRORS, &blk) click to toggle source
# File lib/retry.rb, line 7
def self.call(no_of_retries: DEFAULT_MAX_NO_OF_RETRIES, rescue_errors: DEFAULT_RESCUE_ERRORS, &blk)
  total_attempts = 0
  begin
    blk.call
  rescue rescue_errors => ex
    total_attempts += 1 
    retry if total_attempts < no_of_retries
  ensure
    if total_attempts == no_of_retries
      return
    end
  end
end