Method: EsClient::ActiveRecord::Glue::ClassMethods#find_in_batches_with_progress

Defined in:
lib/es_client/active_record/glue.rb

#find_in_batches_with_progress(options = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/es_client/active_record/glue.rb', line 53

def find_in_batches_with_progress(options = {})
  unless defined? ProgressBar
    warn "Install 'ruby-progressbar' gem to use '#{__method__}' method"
    return
  end
  options[:batch_size] ||= 1000
  total = (count / options[:batch_size].to_f).ceil
  title = options.delete(:name) || "#{name} batch_size:#{options[:batch_size]}"
  bar = ProgressBar.create(title: title, total: total, format: '%c of %C - %a %e |%b>>%i| %p%% %t')
  bar.progress_mark = '='
  find_in_batches(options) do |r|
    yield r
    bar.increment
  end
  bar.finish
end