class PeopleGroup::Utils

Public Class Methods

retry_on_error(max_attempts: 3, delay: 0, errors: [StandardError], on_error: -> {} { || ... } click to toggle source
# File lib/peoplegroup/utils.rb, line 6
def retry_on_error(max_attempts: 3, delay: 0, errors: [StandardError], on_error: -> {})
  attempts = 0

  begin
    yield
  rescue *errors => e
    on_error.call
    sleep delay
    retry if (attempts += 1) < max_attempts
    raise e
  end
end