Class: CapistranoMulticonfigParallel::TerminalTable
- Inherits:
-
Object
- Object
- CapistranoMulticonfigParallel::TerminalTable
- Extended by:
- Forwardable
- Includes:
- BaseActorHelper
- Defined in:
- lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb
Overview
class used to display the progress of each worker on terminal screen using a table
Direct Known Subclasses
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#job_manager ⇒ Object
readonly
Returns the value of attribute job_manager.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#screen_erased ⇒ Object
readonly
Returns the value of attribute screen_erased.
-
#terminal_rows ⇒ Object
readonly
Returns the value of attribute terminal_rows.
Class Method Summary collapse
Instance Method Summary collapse
- #default_heaadings ⇒ Object
- #display_table_on_terminal(table, jobs) ⇒ Object
- #fetch_table_size(jobs) ⇒ Object
-
#initialize(manager, job_manager, options = {}) ⇒ TerminalTable
constructor
A new instance of TerminalTable.
- #managers_alive? ⇒ Boolean
- #notify_time_change(_channel, message) ⇒ Object
- #print_errors ⇒ Object
- #rescue_exception(ex) ⇒ Object
- #run ⇒ Object
- #setup_table_jobs(table) ⇒ Object
- #show_confirmation(message, default) ⇒ Object
- #signal_complete ⇒ Object
Methods included from BaseActorHelper
Constructor Details
#initialize(manager, job_manager, options = {}) ⇒ TerminalTable
Returns a new instance of TerminalTable.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 18 def initialize(manager, job_manager, = {}) @manager = manager @position = nil @terminal_rows = nil @cursor = CapistranoMulticonfigParallel::Cursor.new @errors = [] @notifications = 0 = .is_a?(Hash) ? .stringify_keys : @job_manager = job_manager @screen_erased = false async.run rescue => ex puts ex.inspect rescue_exception(ex) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 9 def errors @errors end |
#job_manager ⇒ Object (readonly)
Returns the value of attribute job_manager.
9 10 11 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 9 def job_manager @job_manager end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
9 10 11 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 9 def manager @manager end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 9 def end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
9 10 11 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 9 def position @position end |
#screen_erased ⇒ Object (readonly)
Returns the value of attribute screen_erased.
9 10 11 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 9 def screen_erased @screen_erased end |
#terminal_rows ⇒ Object (readonly)
Returns the value of attribute terminal_rows.
9 10 11 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 9 def terminal_rows @terminal_rows end |
Class Method Details
.topic ⇒ Object
14 15 16 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 14 def self.topic 'sshkit_terminal' end |
Instance Method Details
#default_heaadings ⇒ Object
34 35 36 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 34 def default_heaadings ['Job UUID', 'App/Stage', 'Action', 'ENV Variables', 'Current Status'] end |
#display_table_on_terminal(table, jobs) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 62 def display_table_on_terminal(table, jobs) table_size = fetch_table_size(jobs) @position, @terminal_rows, @screen_erased = @cursor.display_on_screen( "#{table}", .merge( position: @position, table_size: table_size, screen_erased: @screen_erased ) ) print_errors end |
#fetch_table_size(jobs) ⇒ Object
57 58 59 60 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 57 def fetch_table_size(jobs) job_rows = jobs.sum { |_job_id, job| job.row_size } (job_rows + 2)**2 end |
#managers_alive? ⇒ Boolean
94 95 96 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 94 def managers_alive? @manager.alive? end |
#notify_time_change(_channel, message) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 42 def notify_time_change(_channel, ) table = Terminal::Table.new(title: 'Deployment Status Table', headings: default_heaadings) jobs = setup_table_jobs(table) @cursor.erase_screen if @notifications.to_i.zero? && @job_manager.checked_job_paths.size > 0 && jobs.find{|job_id, job| job.bundler_check_status.present? }.present? @notifications=@notifications+1 display_table_on_terminal(table, jobs) signal_complete end |
#print_errors ⇒ Object
75 76 77 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 75 def print_errors puts(@errors.join("\n")) if @errors.present? && .fetch('clear_screen', false).to_s == 'false' && development_debug? end |
#rescue_exception(ex) ⇒ Object
51 52 53 54 55 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 51 def rescue_exception(ex) log_to_file("Terminal Table client disconnected due to error #{ex.inspect}") rescue_error(ex, 'stderr') terminate end |
#run ⇒ Object
38 39 40 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 38 def run subscribe(CapistranoMulticonfigParallel::TerminalTable.topic, :notify_time_change) end |
#setup_table_jobs(table) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 79 def setup_table_jobs(table) jobs = managers_alive? ? @manager.jobs.dup : [] jobs.each do |job_id, job| table.add_row(job.terminal_row) table.add_separator if jobs.keys.last != job_id end jobs end |
#show_confirmation(message, default) ⇒ Object
88 89 90 91 92 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 88 def show_confirmation(, default) exclusive do ask_confirm(, default) end end |
#signal_complete ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 98 def signal_complete if managers_alive? && @manager.all_workers_finished? && workers_terminated.instance_variable_get("@waiters").blank? condition.signal('completed') if condition.instance_variable_get("@waiters").present? elsif !managers_alive? terminate end end |