Sha256: 09b88e3d7f9d270fa464a823056accfa1790a35dfccfcf9b54d0f5b79998fe11

Contents?: true

Size: 1.48 KB

Versions: 36

Compression:

Stored size: 1.48 KB

Contents

require 'webmachine'
require 'pact_broker/db'
require 'pact_broker/logging'

module PactBroker
  module Diagnostic
    module Resources
      class Dependencies < Webmachine::Resource

        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" => request.uri.to_s
              }
            }
          }.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

36 entries across 36 versions & 1 rubygems

Version Path
pact_broker-1.13.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.12.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.11.2 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.11.1 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.11.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.10.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.9.3 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.9.2 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.9.1 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.9.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.9.0.rc1 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.8.1 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.8.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.7.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.6.0 lib/pact_broker/diagnostic/resources/dependencies.rb
pact_broker-1.5.0 lib/pact_broker/diagnostic/resources/dependencies.rb