diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d25164..3665854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - Added `_all` and `default_fields` options - Added global `index_prefix` option +- Added `wait` option to async reindex +- Raise error for `reindex_status` when Redis not configured ## 2.3.1 diff --git a/lib/searchkick.rb b/lib/searchkick.rb index ba80fe7..77cad74 100644 --- a/lib/searchkick.rb +++ b/lib/searchkick.rb @@ -153,6 +153,8 @@ module Searchkick completed: batches_left == 0, batches_left: batches_left } + else + raise Searchkick::Error, "Redis not configured" end end diff --git a/lib/searchkick/index.rb b/lib/searchkick/index.rb index 95ebafa..2b6fc81 100644 --- a/lib/searchkick/index.rb +++ b/lib/searchkick/index.rb @@ -228,7 +228,8 @@ module Searchkick end # check if alias exists - if alias_exists? + alias_exists = alias_exists? + if alias_exists # import before promotion index.import_scope(scope, resume: resume, async: async, full: true) if import @@ -246,6 +247,24 @@ module Searchkick end if async + if async.is_a?(Hash) && async[:wait] + puts "Created index: #{index.name}" + puts "Jobs queued. Waiting..." + loop do + sleep 3 + status = Searchkick.reindex_status(index.name) + break if status[:completed] + puts "Batches left: #{status[:batches_left]}" + end + # already promoted if alias didn't exist + if alias_exists + puts "Jobs complete. Promoting..." + promote(index.name, update_refresh_interval: !refresh_interval.nil?) + end + clean_indices unless retain + puts "SUCCESS!" + end + {index_name: index.name} else index.refresh -- libgit2 0.21.0