Sha256: ac1e353baeb7f01e73773e737ba8e695e2719e2b0e306bd7cbb24e50a199643b
Contents?: true
Size: 1.5 KB
Versions: 121
Compression:
Stored size: 1.5 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" => 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
121 entries across 121 versions & 1 rubygems