Skip to content

Commit

Permalink
Move the ping method into the repository
Browse files Browse the repository at this point in the history
This will allow different types of repositories to add their own ping
handler
  • Loading branch information
jcoyne committed Jun 27, 2018
1 parent ac2ad4a commit 2a6e502
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
6 changes: 6 additions & 0 deletions lib/blacklight/abstract_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def search(_params = {})
raise NotImplementedError
end

##
# Is the repository in a working state?
def ping
raise NotImplementedError
end

private

def connection_config
Expand Down
8 changes: 8 additions & 0 deletions lib/blacklight/solr/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def search params = {}
send_and_receive blacklight_config.solr_path, params.reverse_merge(qt: blacklight_config.qt)
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
# @see [RSolr::Client#send_and_receive]
Expand Down
15 changes: 2 additions & 13 deletions lib/railties/blacklight.rake
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,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|
Expand Down

0 comments on commit 2a6e502

Please sign in to comment.