Sha256: 2e258c2eae2c60fec2270a9238dfbeeb0d28e8d0acf078cb472765489d6a0d56

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

# encoding: utf-8
require "moped/failover/disconnect"
require "moped/failover/ignore"
require "moped/failover/reconfigure"
require "moped/failover/retry"

module Moped

  # Provides behaviour around failover scenarios for different types of
  # exceptions that get raised on connection and execution of operations.
  #
  # @since 2.0.0
  module Failover
    extend self

    # Hash lookup for the failover classes based off the exception type.
    #
    # @since 2.0.0
    STRATEGIES = {
      Errors::AuthenticationFailure => Ignore,
      Errors::ConnectionFailure => Retry,
      Errors::CursorNotFound => Ignore,
      Errors::OperationFailure => Reconfigure,
      Errors::QueryFailure => Reconfigure,
      Errors::PoolTimeout => Retry
    }.freeze

    # Get the appropriate failover handler given the provided exception.
    #
    # @example Get the failover handler for an IOError.
    #   Moped::Failover.get(IOError)
    #
    # @param [ Exception ] exception The raised exception.
    #
    # @return [ Object ] The failover handler.
    #
    # @since 2.0.0
    def get(exception)
      STRATEGIES.fetch(exception.class, Disconnect)
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/bundler/gems/moped-cf817ca58a85/lib/moped/failover.rb
moped-2.0.7 lib/moped/failover.rb