class Impala::ProgressReporter
Attributes
cursor[RW]
Public Class Methods
new(cursor, options = {})
click to toggle source
# File lib/impala/progress_reporter.rb 3 def initialize(cursor, options = {}) 4 @cursor = cursor 5 @progress_every = options.fetch(:progress_every, 60).to_f 6 @show_progress = options.fetch(:show_progress, false) 7 @start_time = @last_progress = Time.now 8 end
Public Instance Methods
report()
click to toggle source
# File lib/impala/progress_reporter.rb 14 def report 15 return unless enough_time_elapsed? 16 @last_progress = Time.now 17 message = sprintf("Progress %.02f%% after %.02f seconds", 18 cursor.progress * 100, 19 total_time_elapsed) 20 progress_stream.puts message 21 end
show?()
click to toggle source
# File lib/impala/progress_reporter.rb 10 def show? 11 @show_progress 12 end
Private Instance Methods
enough_time_elapsed?()
click to toggle source
# File lib/impala/progress_reporter.rb 32 def enough_time_elapsed? 33 (Time.now - last_progress) > progress_every 34 end
progress_stream()
click to toggle source
# File lib/impala/progress_reporter.rb 27 def progress_stream 28 return show_progress if show_progress.is_a?(IO) 29 STDERR 30 end
total_time_elapsed()
click to toggle source
# File lib/impala/progress_reporter.rb 36 def total_time_elapsed 37 (Time.now - start_time) 38 end