Commit 0e7bcb088ee44ff55bf22e87a9dc8b406cf968f8

Authored by Andrew Kane
1 parent 6e9e06f5

Improved output for reindex rake task

Showing 2 changed files with 12 additions and 11 deletions   Show diff stats
CHANGELOG.md
1 1 ## 4.4.1 (unreleased)
2 2  
3 3 - Improved error message for `reload_synonyms` with non-OSS version of Elasticsearch
  4 +- Improved output for reindex rake task
4 5  
5 6 ## 4.4.0 (2020-06-17)
6 7  
... ...
lib/tasks/searchkick.rake
1 1 namespace :searchkick do
2   - desc "reindex model"
  2 + desc "reindex a model"
3 3 task reindex: :environment do
4   - if ENV["CLASS"]
5   - klass = ENV["CLASS"].safe_constantize
6   - if klass
7   - klass.reindex
8   - else
9   - abort "Could not find class: #{ENV['CLASS']}"
10   - end
11   - else
12   - abort "USAGE: rake searchkick:reindex CLASS=Product"
13   - end
  4 + class_name = ENV["CLASS"]
  5 + abort "USAGE: rake searchkick:reindex CLASS=Product" unless class_name
  6 +
  7 + model = class_name.safe_constantize
  8 + abort "Could not find class: #{class_name}" unless model
  9 + abort "#{class_name} is not a searchkick model" unless Searchkick.models.include?(model)
  10 +
  11 + puts "Reindexing #{model.name}..."
  12 + model.reindex
  13 + puts "Reindex successful"
14 14 end
15 15  
16 16 namespace :reindex do
... ...