Commit 3f6d9d24ce49fa863560e5b02c02d64e38e7c020
1 parent
5532ca79
Exists in
master
and in
19 other branches
Fixed retries for BulkReindexJob
Showing
2 changed files
with
25 additions
and
12 deletions
Show diff stats
lib/searchkick/bulk_reindex_job.rb
... | ... | @@ -6,16 +6,14 @@ module Searchkick |
6 | 6 | klass = class_name.constantize |
7 | 7 | index = index_name ? Searchkick::Index.new(index_name) : klass.searchkick_index |
8 | 8 | record_ids ||= min_id..max_id |
9 | - Searchkick.callbacks(:bulk) do | |
10 | - index.import_scope( | |
11 | - Searchkick.load_records(klass, record_ids), | |
12 | - method_name: method_name, | |
13 | - batch: true, | |
14 | - batch_id: batch_id, | |
15 | - delete_missing: delete_missing, | |
16 | - record_ids: record_ids | |
17 | - ) | |
18 | - end | |
9 | + index.import_scope( | |
10 | + Searchkick.load_records(klass, record_ids), | |
11 | + method_name: method_name, | |
12 | + batch: true, | |
13 | + batch_id: batch_id, | |
14 | + delete_missing: delete_missing, | |
15 | + record_ids: record_ids | |
16 | + ) | |
19 | 17 | end |
20 | 18 | end |
21 | 19 | end | ... | ... |
lib/searchkick/index.rb
... | ... | @@ -445,8 +445,12 @@ module Searchkick |
445 | 445 | |
446 | 446 | begin |
447 | 447 | # bulk reindex |
448 | - method_name ? bulk_update(records, method_name) : import(records) | |
449 | - bulk_delete(delete_records) | |
448 | + possibly_bulk do | |
449 | + if records.any? | |
450 | + method_name ? bulk_update(records, method_name) : import(records) | |
451 | + end | |
452 | + bulk_delete(delete_records) if delete_records.any? | |
453 | + end | |
450 | 454 | rescue Faraday::ClientError => e |
451 | 455 | if retries < 1 |
452 | 456 | retries += 1 |
... | ... | @@ -458,6 +462,17 @@ module Searchkick |
458 | 462 | end |
459 | 463 | end |
460 | 464 | |
465 | + # use bulk if no callbacks value set | |
466 | + def possibly_bulk | |
467 | + if Searchkick.callbacks_value | |
468 | + yield | |
469 | + else | |
470 | + Searchkick.callbacks(:bulk) do | |
471 | + yield | |
472 | + end | |
473 | + end | |
474 | + end | |
475 | + | |
461 | 476 | def batches_key |
462 | 477 | "searchkick:reindex:#{name}:batches" |
463 | 478 | end | ... | ... |