class Mongo::Retry

Constants

DEFAULT_OPTIONS
DEFAULT_RETRYABLE_EXCEPTIONS
DEFAULT_RETRY_SLEEPS

Public Class Methods

new(connection, options = {}) click to toggle source
# File lib/mongo/retry.rb, line 20
def initialize(connection, options = {})
  @options = DEFAULT_OPTIONS.merge(options)
  @connection = connection
end

Public Instance Methods

connection_guard(retries = @options[:retries].dup) { || ... } click to toggle source
# File lib/mongo/retry.rb, line 25
def connection_guard(retries = @options[:retries].dup)
  yield
rescue *@options[:exceptions] => e
  if retry_timeout = retries.pop
    log(:retry, e)
    @options[:delayer].call(retry_timeout)
    reconnect!
    retry
  else
    log(:fail, e)
    raise e
  end
end

Private Instance Methods

log(reason, exception) click to toggle source
# File lib/mongo/retry.rb, line 41
def log(reason, exception)
  if @options[:logger]
    @options[:logger].call(reason, exception)
  end
end
reconnect!() click to toggle source
# File lib/mongo/retry.rb, line 47
def reconnect!
  @connection.reconnect
rescue *@options[:retry_exceptions] => e
  log(:reconnect, e)
end