Class: CapistranoMulticonfigParallel::TerminalTable
- Inherits:
-
Object
- Object
- CapistranoMulticonfigParallel::TerminalTable
- Includes:
- ApplicationHelper, Celluloid, Celluloid::Logger, Celluloid::Notifications
- 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
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 ApplicationHelper
action_confirmed?, fetch_parsed_string, fetch_remaining_arguments, find_remaining_args, get_question_details, msg_for_stdin?, msg_for_task?, parse_task_string, percent_of, regex_last_match, setup_command_line_standard, wrap_string
Methods included from CapistranoHelper
env_key_format, env_prefix, filtered_env_keys_format, setup_flags_for_job, trace_flag
Methods included from GemHelper
fetch_gem_version, find_loaded_gem, find_loaded_gem_property, get_parsed_version, verify_gem_version
Methods included from StagesHelper
app_names_from_stages, check_stage_path, checks_paths, fetch_stages_app, fetch_stages_from_file, fetch_stages_paths, independent_deploy?, multi_apps?, sorted_paths, stages, stages_paths, stages_root
Methods included from ParseHelper
check_hash_set, check_numeric, strip_characters_from_string, value_is_array?, verify_array_of_strings, verify_empty_options, warn_array_without_strings
Methods included from CoreHelper
app_debug_enabled?, ask_confirm, ask_stdout_confirmation, check_terminal_tty, debug_websocket?, error_filtered?, execute_with_rescue, find_worker_log, force_confirmation, format_error, log_error, log_output_error, log_to_file, multi_fetch_argv, print_to_log_file, rescue_error, rescue_interrupt, setup_filename_logger, setup_logger_formatter, show_warning, terminal_actor, terminal_errors?, websocket_config, websocket_server_config
Methods included from InternalHelper
arg_is_in_default_config?, check_file, create_log_file, custom_commands, default_config_keys, default_internal_config, default_internal_configuration_params, detect_root, enable_main_log_file, fail_capfile_not_found, fetch_default_internal_config, find_config_type, find_env_multi_cap_root, find_file_in_directory, internal_config_directory, internal_config_file, log_directory, main_log_file, multi_level_prop, pathname_is_root?, pwd_directory, pwd_parent_dir, root, setup_default_configuration_types, sliced_default_config, try_detect_file
Constructor Details
#initialize(manager, job_manager, options = {}) ⇒ TerminalTable
Returns a new instance of TerminalTable.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 17 def initialize(manager, job_manager, = {}) @manager = manager @position = nil @terminal_rows = nil @errors = [] @options = .is_a?(Hash) ? .stringify_keys : @job_manager = job_manager @screen_erased = false async.run rescue => ex rescue_exception(ex) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 11 def errors @errors end |
#job_manager ⇒ Object (readonly)
Returns the value of attribute job_manager.
11 12 13 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 11 def job_manager @job_manager end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
11 12 13 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 11 def manager @manager end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 11 def @options end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
11 12 13 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 11 def position @position end |
#screen_erased ⇒ Object (readonly)
Returns the value of attribute screen_erased.
11 12 13 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 11 def screen_erased @screen_erased end |
#terminal_rows ⇒ Object (readonly)
Returns the value of attribute terminal_rows.
11 12 13 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 11 def terminal_rows @terminal_rows end |
Class Method Details
.topic ⇒ Object
13 14 15 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 13 def self.topic 'sshkit_terminal' end |
Instance Method Details
#default_heaadings ⇒ Object
30 31 32 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 30 def default_heaadings ['Job UUID', 'App/Stage', 'Action', 'ENV Variables', 'Current Status'] end |
#display_table_on_terminal(table, jobs) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 55 def display_table_on_terminal(table, jobs) table_size = fetch_table_size(jobs) @position, @terminal_rows, @screen_erased = CapistranoMulticonfigParallel::Cursor.display_on_screen( "#{table}", @options.merge( position: @position, table_size: table_size, screen_erased: @screen_erased ) ) print_errors signal_complete end |
#fetch_table_size(jobs) ⇒ Object
50 51 52 53 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 50 def fetch_table_size(jobs) job_rows = jobs.sum { |_job_id, job| job.row_size } (job_rows + 2)**2 end |
#managers_alive? ⇒ Boolean
88 89 90 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 88 def managers_alive? @job_manager.alive? && @manager.alive? end |
#notify_time_change(_channel, _message) ⇒ Object
38 39 40 41 42 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 38 def notify_time_change(_channel, ) table = Terminal::Table.new(title: 'Deployment Status Table', headings: default_heaadings) jobs = setup_table_jobs(table) display_table_on_terminal(table, jobs) end |
#print_errors ⇒ Object
69 70 71 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 69 def print_errors puts(@errors.join("\n")) if @errors.present? && @options.fetch('clear_screen', false).to_s == 'false' end |
#rescue_exception(ex) ⇒ Object
44 45 46 47 48 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 44 def rescue_exception(ex) log_to_file("Terminal Table client disconnected due to error #{ex.inspect}") rescue_error(ex, 'stderr') terminate end |
#run ⇒ Object
34 35 36 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 34 def run subscribe(CapistranoMulticonfigParallel::TerminalTable.topic, :notify_time_change) end |
#setup_table_jobs(table) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 73 def setup_table_jobs(table) jobs = @manager.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
82 83 84 85 86 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 82 def show_confirmation(, default) exclusive do ask_confirm(, default) end end |
#signal_complete ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 92 def signal_complete if managers_alive? && @manager.all_workers_finished? @job_manager.condition.signal('completed') if @job_manager.alive? elsif !managers_alive? terminate end end |