class Mongo::Retryable::BaseWorker

The abstract superclass for workers employed by Mongo::Retryable.

@api private

Attributes

retryable[R]

@return [ Mongo::Retryable ] retryable A reference to the client object

that instatiated this worker.

Public Class Methods

new(retryable) click to toggle source

Constructs a new worker.

@example Instantiating a new read worker

worker = Mongo::Retryable::ReadWorker.new(self)

@example Instantiating a new write worker

worker = Mongo::Retryable::WriteWorker.new(self)

@param [ Mongo::Retryable ] retryable The client object that is using

this worker to perform a retryable operation
# File lib/mongo/retryable/base_worker.rb, line 45
def initialize(retryable)
  @retryable = retryable
end

Private Instance Methods

deprecation_warning(key, warning) click to toggle source

Logs the given deprecation warning the first time it is called for a given key; after that, it does nothing when given the same key.

# File lib/mongo/retryable/base_worker.rb, line 74
def deprecation_warning(key, warning)
  $_deprecation_warnings ||= {}
  unless $_deprecation_warnings[key]
    $_deprecation_warnings[key] = true
    Logger.logger.warn(warning)
  end
end
is_retryable_exception?(e) click to toggle source

Tests to see if the given exception instance is of a type that can be retried.

@return [ true | false ] true if the exception is retryable.

# File lib/mongo/retryable/base_worker.rb, line 68
def is_retryable_exception?(e)
  retryable_exceptions.any? { |klass| klass === e }
end
log_retry(e, options = nil) click to toggle source

Log a warning so that any application slow down is immediately obvious.

# File lib/mongo/retryable/base_worker.rb, line 83
def log_retry(e, options = nil)
  message = (options || {}).fetch(:message, "Retry")
  Logger.logger.warn "#{message} due to: #{e.class.name}: #{e.message}"
end
retryable_exceptions() click to toggle source

Indicate which exception classes that are generally retryable.

@return [ Array<Mongo:Error> ] Array of exception classes that are

considered retryable.
# File lib/mongo/retryable/base_worker.rb, line 55
def retryable_exceptions
  [
    Error::ConnectionPerished,
    Error::ServerNotUsable,
    Error::SocketError,
    Error::SocketTimeoutError
  ].freeze
end