Class: Gorgon::ProgressBarView
- Inherits:
-
Object
- Object
- Gorgon::ProgressBarView
- Defined in:
- lib/gorgon/progress_bar_view.rb
Constant Summary collapse
- MAX_LENGTH =
200
- LOADING_MSG =
"Loading environment and workers..."
- RUNNING_MSG =
"Running files:"
- LEGEND_MSG =
"Legend:\nF - failure files count\nH - number of hosts that have run files\nW - number of workers running files"
- PROGRESS_BAR_REFRESH_RATE =
0.5
Instance Method Summary collapse
- #create_progress_bar_if_started_job_running ⇒ Object
-
#initialize(job_state) ⇒ ProgressBarView
constructor
-
because the resolution of the elapsed time is one second, we use the nyquist frequency of 0.5 seconds en.wikipedia.org/wiki/Nyquist_frequency.
-
- #show ⇒ Object
- #update(payload = {}) ⇒ Object
- #update_elapsed_time ⇒ Object
Constructor Details
#initialize(job_state) ⇒ ProgressBarView
-
because the resolution of the elapsed time is one second, we use the nyquist frequency of 0.5 seconds
17 18 19 20 21 |
# File 'lib/gorgon/progress_bar_view.rb', line 17 def initialize job_state @job_state = job_state @job_state.add_observer(self) @timer = EventMachine::PeriodicTimer.new(PROGRESS_BAR_REFRESH_RATE) { update_elapsed_time } end |
Instance Method Details
#create_progress_bar_if_started_job_running ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/gorgon/progress_bar_view.rb', line 49 def if @progress_bar.nil? && @job_state.state == :running print "\r#{' ' * (LOADING_MSG.length)}\r" puts LEGEND_MSG @progress_bar = ProgressBar.create(:total => @job_state.total_files, :length => [terminal_length, MAX_LENGTH].min, :format => format(bar: :green, title: :white)); end end |
#show ⇒ Object
23 24 25 |
# File 'lib/gorgon/progress_bar_view.rb', line 23 def show print LOADING_MSG end |
#update(payload = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gorgon/progress_bar_view.rb', line 27 def update payload={} payload if gorgon_crashed? payload return if @progress_bar.nil? || @finished failed_files_count = @job_state.failed_files_count @progress_bar.title=" F: #{failed_files_count} H: #{@job_state.total_running_hosts} W: #{@job_state.total_running_workers}" if failed_files_count > 0 @progress_bar.format(format(bar: :red, title: :default)) end @progress_bar.progress = @job_state.finished_files_count if @job_state.is_job_complete? || @job_state.is_job_cancelled? @finished = true print_summary end end |
#update_elapsed_time ⇒ Object
59 60 61 62 |
# File 'lib/gorgon/progress_bar_view.rb', line 59 def update_elapsed_time @timer.cancel if @finished @progress_bar.refresh if @progress_bar end |