Commit 4f3e6b4a490769185f6a02cbed33342cb5aab869
1 parent
3f6d9d24
Exists in
master
and in
19 other branches
Separate method for tries [skip ci]
Showing
1 changed file
with
15 additions
and
8 deletions
Show diff stats
lib/searchkick/index.rb
... | ... | @@ -432,7 +432,6 @@ module Searchkick |
432 | 432 | method_name: method_name ? method_name.to_s : nil |
433 | 433 | ) |
434 | 434 | else |
435 | - retries = 0 | |
436 | 435 | records = records.select(&:should_index?) |
437 | 436 | |
438 | 437 | delete_records = |
... | ... | @@ -443,7 +442,7 @@ module Searchkick |
443 | 442 | [] |
444 | 443 | end |
445 | 444 | |
446 | - begin | |
445 | + with_retries do | |
447 | 446 | # bulk reindex |
448 | 447 | possibly_bulk do |
449 | 448 | if records.any? |
... | ... | @@ -451,17 +450,25 @@ module Searchkick |
451 | 450 | end |
452 | 451 | bulk_delete(delete_records) if delete_records.any? |
453 | 452 | end |
454 | - rescue Faraday::ClientError => e | |
455 | - if retries < 1 | |
456 | - retries += 1 | |
457 | - retry | |
458 | - end | |
459 | - raise e | |
460 | 453 | end |
461 | 454 | end |
462 | 455 | end |
463 | 456 | end |
464 | 457 | |
458 | + def with_retries | |
459 | + retries = 0 | |
460 | + | |
461 | + begin | |
462 | + yield | |
463 | + rescue Faraday::ClientError => e | |
464 | + if retries < 1 | |
465 | + retries += 1 | |
466 | + retry | |
467 | + end | |
468 | + raise e | |
469 | + end | |
470 | + end | |
471 | + | |
465 | 472 | # use bulk if no callbacks value set |
466 | 473 | def possibly_bulk |
467 | 474 | if Searchkick.callbacks_value | ... | ... |