From 8809982af1d111246a7dd9d57cb1d135d0aa5408 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 27 Jun 2018 11:34:59 -0500 Subject: [PATCH] Move the ping method into the repository This will allow different types of repositories to add their own ping handler --- lib/blacklight/abstract_repository.rb | 7 ++++++- lib/blacklight/solr/repository.rb | 8 ++++++++ lib/railties/blacklight.rake | 15 ++------------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/blacklight/abstract_repository.rb b/lib/blacklight/abstract_repository.rb index 274663803c..9fe7a5c26f 100644 --- a/lib/blacklight/abstract_repository.rb +++ b/lib/blacklight/abstract_repository.rb @@ -32,13 +32,18 @@ def search(_params = {}) raise NotImplementedError end - ## # Query the fields that exist from the index # @return [Hash] def reflect_fields raise NotImplementedError end + ## + # Is the repository in a working state? + def ping + raise NotImplementedError + end + private def connection_config diff --git a/lib/blacklight/solr/repository.rb b/lib/blacklight/solr/repository.rb index ee49a2adff..88df53457a 100644 --- a/lib/blacklight/solr/repository.rb +++ b/lib/blacklight/solr/repository.rb @@ -36,6 +36,14 @@ def reflect_fields send_and_receive('admin/luke', params: { fl: '*', 'json.nl' => 'map' })['fields'] end + ## + # @return [boolean] true if the repository is reachable + def ping + response = connection.send_and_receive 'admin/ping', {} + Blacklight.logger.info("Ping [#{connection.uri}] returned: '#{response['status']}'") + response['status'] == "OK" + end + ## # Execute a solr query # TODO: Make this private after we have a way to abstract admin/luke and ping diff --git a/lib/railties/blacklight.rake b/lib/railties/blacklight.rake index 1ce95711d6..4508c72dd9 100644 --- a/lib/railties/blacklight.rake +++ b/lib/railties/blacklight.rake @@ -27,23 +27,12 @@ namespace :blacklight do namespace :check do desc "Check the Solr connection and controller configuration" task :solr, [:controller_name] => [:environment] do - errors = 0 - verbose = ENV.fetch('VERBOSE', false).present? - - conn = Blacklight.default_index.connection - puts "[#{conn.uri}]" - - print " - admin/ping: " begin - response = conn.send_and_receive 'admin/ping', {} - puts response['status'] - errors += 1 unless response['status'] == "OK" + exit 1 unless Blacklight.default_index.ping rescue => e - errors += 1 puts e.to_s + exit 1 end - - exit 1 if errors > 0 end task :controller, [:controller_name] => [:environment] do |_, args|