Class: Elastics::ProgBar
- Inherits:
-
Object
- Object
- Elastics::ProgBar
- Defined in:
- lib/elastics/prog_bar.rb
Instance Attribute Summary collapse
-
#pbar ⇒ Object
readonly
Returns the value of attribute pbar.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(total_count, batch_size = nil, prefix_message = nil) ⇒ ProgBar
constructor
A new instance of ProgBar.
- #process_result(result, inc) ⇒ Object
Constructor Details
#initialize(total_count, batch_size = nil, prefix_message = nil) ⇒ ProgBar
Returns a new instance of ProgBar.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/elastics/prog_bar.rb', line 6 def initialize(total_count, batch_size=nil, =nil) @successful_count = 0 @failed_count = 0 puts = "#{}Processing #{total_count} documents" << " in batches of #{batch_size}" unless batch_size.nil? Prompter.say_log @pbar = ::ProgressBar.create(:title => title(:ok), :total => total_count, :progress_mark => (Dye.color? ? ' ' : '|'), :format => ('%t%c/%C %p%% %E %b' + dye(:background, '%i', '%i'))) end |
Instance Attribute Details
#pbar ⇒ Object (readonly)
Returns the value of attribute pbar.
4 5 6 |
# File 'lib/elastics/prog_bar.rb', line 4 def @pbar end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
4 5 6 |
# File 'lib/elastics/prog_bar.rb', line 4 def total_count @total_count end |
Instance Method Details
#finish ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/elastics/prog_bar.rb', line 35 def finish @pbar.finish unless @pbar.finished? Prompter.say_log "Processed #{@pbar.total}. " Prompter.say_ok "Successful #{@successful_count}. " Prompter.say_notice "Skipped #{@pbar.total - @successful_count - @failed_count}. " Prompter.say_warning "Failed #{@failed_count}.", :mute => true Prompter.say_warning "See the log for the details about the #{@failed_count} failures." unless @failed_count == 0 end |
#process_result(result, inc) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/elastics/prog_bar.rb', line 19 def process_result(result, inc) unless result.nil? || result.empty? if result.failed.size > 0 Conf.logger.error "Failed load:\n#{result.failed.to_yaml}" @pbar.title = title(:failed) @pbar.progress_mark = 'F' unless Dye.color? end @failed_count += result.failed.size @successful_count += result.successful.size end new_progress = @pbar.progress + inc # avoids an error in case progress > total (may happen in import) @pbar.total = (new_progress + 1) if new_progress > @pbar.total @pbar.progress = new_progress end |