Sha256: 6a8e4799c951b2c5e9f19e74bb82756da0c594878e3eb50aa4fbb6bcce7570da

Contents?: true

Size: 1.05 KB

Versions: 20

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Orchestration
  module Services
    module Mongo
      class Healthcheck
        include HealthcheckBase

        dependencies 'mongoid'

        def connection_errors
          return [Moped::Errors::ConnectionFailure] if defined?(Moped)

          [::Mongo::Error::NoServerAvailable]
        end

        def connect
          silence_warnings

          # REVIEW: For some reason this is extremely slow. Worth trying
          # to see if there's a faster way to fail.
          Mongoid.load_configuration(@configuration.settings)
          !default_client.database_names.empty?
        end

        private

        def default_client
          return Mongoid.default_client if Mongoid.respond_to?(:default_client)

          # Support older versions of Mongoid
          Mongoid.default_session
        end

        def silence_warnings
          if defined?(Moped)
            Moped.logger = Logger.new(devnull)
          else
            Mongoid.logger = Logger.new(devnull)
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
orchestration-0.3.17 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.16 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.15 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.14 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.13 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.12 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.11 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.10 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.9 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.8 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.7 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.6 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.5 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.4 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.3 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.2 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.1 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.3.0 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.2.8 lib/orchestration/services/mongo/healthcheck.rb
orchestration-0.2.7 lib/orchestration/services/mongo/healthcheck.rb