Commit 03e0107dd00e0bc152a9162799cdf21fec1b7b3a
1 parent
04974017
Exists in
master
and in
2 other branches
Prefer mode: :async over async: true for full reindex
Showing
2 changed files
with
24 additions
and
5 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/index.rb
... | ... | @@ -237,6 +237,19 @@ module Searchkick |
237 | 237 | self.refresh if refresh |
238 | 238 | true |
239 | 239 | else |
240 | + async = options.delete(:async) | |
241 | + if async | |
242 | + if async.is_a?(Hash) && async[:wait] | |
243 | + # TODO warn in 5.1 | |
244 | + # Searchkick.warn "async option is deprecated - use mode: :async, wait: true instead" | |
245 | + options[:wait] = true unless options.key?(:wait) | |
246 | + else | |
247 | + # TODO warn in 5.1 | |
248 | + # Searchkick.warn "async option is deprecated - use mode: :async instead" | |
249 | + end | |
250 | + options[:mode] ||= :async | |
251 | + end | |
252 | + | |
240 | 253 | full_reindex(relation, **options) |
241 | 254 | end |
242 | 255 | end |
... | ... | @@ -337,7 +350,9 @@ module Searchkick |
337 | 350 | # https://gist.github.com/jarosan/3124884 |
338 | 351 | # http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/ |
339 | 352 | # TODO deprecate async in favor of mode: :async, wait: true/false |
340 | - def full_reindex(relation, import: true, resume: false, retain: false, async: false, refresh_interval: nil, scope: nil) | |
353 | + def full_reindex(relation, import: true, resume: false, retain: false, mode: nil, refresh_interval: nil, scope: nil, wait: nil) | |
354 | + raise ArgumentError, "wait only available in :async mode" if !wait.nil? && mode != :async | |
355 | + | |
341 | 356 | if resume |
342 | 357 | index_name = all_indices.sort.last |
343 | 358 | raise Searchkick::Error, "No index to resume" unless index_name |
... | ... | @@ -351,7 +366,7 @@ module Searchkick |
351 | 366 | end |
352 | 367 | |
353 | 368 | import_options = { |
354 | - mode: (async ? :async : :inline), | |
369 | + mode: mode, | |
355 | 370 | full: true, |
356 | 371 | resume: resume, |
357 | 372 | scope: scope |
... | ... | @@ -365,7 +380,7 @@ module Searchkick |
365 | 380 | import_before_promotion(index, relation, **import_options) if import |
366 | 381 | |
367 | 382 | # get existing indices to remove |
368 | - unless async | |
383 | + unless mode == :async | |
369 | 384 | check_uuid(uuid, index.uuid) |
370 | 385 | promote(index.name, update_refresh_interval: !refresh_interval.nil?) |
371 | 386 | clean_indices unless retain |
... | ... | @@ -378,8 +393,8 @@ module Searchkick |
378 | 393 | index.import_scope(relation, **import_options) if import |
379 | 394 | end |
380 | 395 | |
381 | - if async | |
382 | - if async.is_a?(Hash) && async[:wait] | |
396 | + if mode == :async | |
397 | + if wait | |
383 | 398 | puts "Created index: #{index.name}" |
384 | 399 | puts "Jobs queued. Waiting..." |
385 | 400 | loop do | ... | ... |