Sha256: 97a9c5291daebcf724484b4565e09380776d3d39181f398856cd2e8fbab910ac

Contents?: true

Size: 1.53 KB

Versions: 41

Compression:

Stored size: 1.53 KB

Contents

require "pact_broker/diagnostic/resources/base_resource"
require "pact_broker/db"
require "pact_broker/logging"

module PactBroker
  module Diagnostic
    module Resources
      class Dependencies < BaseResource

        include Logging

        def initialize
          @return_status = 200
        end

        def allowed_methods
          ["GET"]
        end

        def content_types_provided
          [["application/hal+json", :to_json]]
        end

        def to_json
          ok, report = database_connectivity_status
          response.body = {
            "database" => report,
            "_links" => {
              "self" => {
                "href" => base_url + "/diagnostic/status/dependencies"
              }
            }
          }.to_json

          ok ? 200 : 500
        end

        private

        def database_connectivity_status
          begin
            valid = valid_database_connection?
            return valid, { "ok" => valid }
          rescue => e
            logger.error "#{e.class} - #{e.message}\n#{e.backtrace.join("\n")}"
            report = {
              "ok" => false,
              "error" => {
                "message" => "#{e.class} - #{e.message}"
              }
            }
            return false, report
          end
        end

        def valid_database_connection?
          connection = PactBroker::DB.connection
          connection.synchronize do |synchronized_connection|
            connection.valid_connection? synchronized_connection
          end
        end
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.111.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.109.1 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.109.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.108.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.107.1 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.107.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.106.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.105.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.104.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.103.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.102.2 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.102.1 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.102.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.101.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.100.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.99.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.98.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-2.97.0 lib/pact_broker/diagnostic/resources/dependencies.rb