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,6 +237,19 @@ module Searchkick | ||
237 | self.refresh if refresh | 237 | self.refresh if refresh |
238 | true | 238 | true |
239 | else | 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 | full_reindex(relation, **options) | 253 | full_reindex(relation, **options) |
241 | end | 254 | end |
242 | end | 255 | end |
@@ -337,7 +350,9 @@ module Searchkick | @@ -337,7 +350,9 @@ module Searchkick | ||
337 | # https://gist.github.com/jarosan/3124884 | 350 | # https://gist.github.com/jarosan/3124884 |
338 | # http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/ | 351 | # http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/ |
339 | # TODO deprecate async in favor of mode: :async, wait: true/false | 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 | if resume | 356 | if resume |
342 | index_name = all_indices.sort.last | 357 | index_name = all_indices.sort.last |
343 | raise Searchkick::Error, "No index to resume" unless index_name | 358 | raise Searchkick::Error, "No index to resume" unless index_name |
@@ -351,7 +366,7 @@ module Searchkick | @@ -351,7 +366,7 @@ module Searchkick | ||
351 | end | 366 | end |
352 | 367 | ||
353 | import_options = { | 368 | import_options = { |
354 | - mode: (async ? :async : :inline), | 369 | + mode: mode, |
355 | full: true, | 370 | full: true, |
356 | resume: resume, | 371 | resume: resume, |
357 | scope: scope | 372 | scope: scope |
@@ -365,7 +380,7 @@ module Searchkick | @@ -365,7 +380,7 @@ module Searchkick | ||
365 | import_before_promotion(index, relation, **import_options) if import | 380 | import_before_promotion(index, relation, **import_options) if import |
366 | 381 | ||
367 | # get existing indices to remove | 382 | # get existing indices to remove |
368 | - unless async | 383 | + unless mode == :async |
369 | check_uuid(uuid, index.uuid) | 384 | check_uuid(uuid, index.uuid) |
370 | promote(index.name, update_refresh_interval: !refresh_interval.nil?) | 385 | promote(index.name, update_refresh_interval: !refresh_interval.nil?) |
371 | clean_indices unless retain | 386 | clean_indices unless retain |
@@ -378,8 +393,8 @@ module Searchkick | @@ -378,8 +393,8 @@ module Searchkick | ||
378 | index.import_scope(relation, **import_options) if import | 393 | index.import_scope(relation, **import_options) if import |
379 | end | 394 | end |
380 | 395 | ||
381 | - if async | ||
382 | - if async.is_a?(Hash) && async[:wait] | 396 | + if mode == :async |
397 | + if wait | ||
383 | puts "Created index: #{index.name}" | 398 | puts "Created index: #{index.name}" |
384 | puts "Jobs queued. Waiting..." | 399 | puts "Jobs queued. Waiting..." |
385 | loop do | 400 | loop do |