Skip to content

Commit

Permalink
Merge pull request #846 from projectblacklight/check-task
Browse files Browse the repository at this point in the history
add blacklight:check rake tasks for checking solr and controller configurations
  • Loading branch information
jcoyne committed Mar 20, 2014
2 parents 949faab + a4040cb commit f42198a
Showing 1 changed file with 94 additions and 1 deletion.
95 changes: 94 additions & 1 deletion lib/railties/blacklight.rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,99 @@ namespace :blacklight do
end
end

end
namespace :check do
desc "Check the Solr connection and controller configuration"
task :solr, [:controller_name] => [:environment] do |_, args|
errors = 0
verbose = ENV.fetch('VERBOSE', false).present?

puts "[#{Blacklight.solr.uri}]"

print " - admin/ping: "
begin
response = Blacklight.solr.send_and_receive 'admin/ping', {}
puts response['status']
errors += 1 unless response['status'] == "OK"
rescue Exception => e
errors += 1
puts e.to_s
end

exit 1 if errors > 0
end

task :controller, [:controller_name] => [:environment] do |_, args|
errors = 0
verbose = ENV.fetch('VERBOSE', false).present?
controller = args[:controller_name].constantize.new if args[:controller_name]
controller ||= CatalogController.new

puts "[#{controller.class.to_s}]"

print " - find: "

begin
response = controller.find q: '{!lucene}*:*'
if response.header['status'] == 0
puts "OK"
else
errors += 1
end

if verbose
puts "\tstatus: #{response.header['status']}"
puts "\tnumFound: #{response.response['numFound']}"
puts "\tdoc count: #{response.docs.length}"
puts "\tfacet fields: #{response.facets.length}"
end
rescue Exception => e
errors += 1
puts e.to_s
end

print " - get_search_results: "

begin
response, docs = controller.get_search_results({}, q: '{!lucene}*:*')

if response.header['status'] == 0 and docs.length > 0
puts "OK"
else
errors += 1
end

if verbose
puts "\tstatus: #{response.header['status']}"
puts "\tnumFound: #{response.response['numFound']}"
puts "\tdoc count: #{docs.length}"
puts "\tfacet fields: #{response.facets.length}"
end
rescue Exception => e
errors += 1
puts e.to_s
end

print " - get_solr_response_for_doc_id: "

begin
doc_id = response.docs.first[SolrDocument.unique_key]
response, doc = controller.get_solr_response_for_doc_id doc_id

if response.header['status'] == 0 and doc
puts "OK"
else
errors += 1
end

if verbose
puts "\tstatus: #{response.header['status']}"
end
rescue Exception => e
errors += 1
puts e.to_s
end

exit 1 if errors > 0
end
end
end

0 comments on commit f42198a

Please sign in to comment.