Commit 083720616dc9ea847b028abb1a47de3b4c2b2503
1 parent
7b6be02b
Exists in
master
and in
19 other branches
Added wait option to reindex sync
Showing
3 changed files
with
24 additions
and
1 deletions
Show diff stats
CHANGELOG.md
lib/searchkick.rb
lib/searchkick/index.rb
... | ... | @@ -228,7 +228,8 @@ module Searchkick |
228 | 228 | end |
229 | 229 | |
230 | 230 | # check if alias exists |
231 | - if alias_exists? | |
231 | + alias_exists = alias_exists? | |
232 | + if alias_exists | |
232 | 233 | # import before promotion |
233 | 234 | index.import_scope(scope, resume: resume, async: async, full: true) if import |
234 | 235 | |
... | ... | @@ -246,6 +247,24 @@ module Searchkick |
246 | 247 | end |
247 | 248 | |
248 | 249 | if async |
250 | + if async.is_a?(Hash) && async[:wait] | |
251 | + puts "Created index: #{index.name}" | |
252 | + puts "Jobs queued. Waiting..." | |
253 | + loop do | |
254 | + sleep 3 | |
255 | + status = Searchkick.reindex_status(index.name) | |
256 | + break if status[:completed] | |
257 | + puts "Batches left: #{status[:batches_left]}" | |
258 | + end | |
259 | + # already promoted if alias didn't exist | |
260 | + if alias_exists | |
261 | + puts "Jobs complete. Promoting..." | |
262 | + promote(index.name, update_refresh_interval: !refresh_interval.nil?) | |
263 | + end | |
264 | + clean_indices unless retain | |
265 | + puts "SUCCESS!" | |
266 | + end | |
267 | + | |
249 | 268 | {index_name: index.name} |
250 | 269 | else |
251 | 270 | index.refresh | ... | ... |