diff --git a/CHANGELOG.md b/CHANGELOG.md index a837899..8a2883e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 4.4.1 (unreleased) - Improved error message for `reload_synonyms` with non-OSS version of Elasticsearch +- Improved output for reindex rake task ## 4.4.0 (2020-06-17) diff --git a/lib/tasks/searchkick.rake b/lib/tasks/searchkick.rake index bd267ee..9865cf7 100644 --- a/lib/tasks/searchkick.rake +++ b/lib/tasks/searchkick.rake @@ -1,16 +1,16 @@ namespace :searchkick do - desc "reindex model" + desc "reindex a model" task reindex: :environment do - if ENV["CLASS"] - klass = ENV["CLASS"].safe_constantize - if klass - klass.reindex - else - abort "Could not find class: #{ENV['CLASS']}" - end - else - abort "USAGE: rake searchkick:reindex CLASS=Product" - end + class_name = ENV["CLASS"] + abort "USAGE: rake searchkick:reindex CLASS=Product" unless class_name + + model = class_name.safe_constantize + abort "Could not find class: #{class_name}" unless model + abort "#{class_name} is not a searchkick model" unless Searchkick.models.include?(model) + + puts "Reindexing #{model.name}..." + model.reindex + puts "Reindex successful" end namespace :reindex do -- libgit2 0.21.0