Class: CapistranoMulticonfigParallel::TerminalTable

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApplicationHelper

action_confirmed?, check_hash_set, check_numeric, fetch_parsed_string, fetch_remaining_arguments, find_loaded_gem, find_remaining_args, get_question_details, msg_for_stdin?, msg_for_task?, multi_fetch_argv, parse_task_string, percent_of, regex_last_match, setup_command_line_standard, strip_characters_from_string, value_is_array?, verify_array_of_strings, verify_empty_options, warn_array_without_strings, wrap_string

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_to_file, print_to_log_file, rescue_error, rescue_interrupt, setup_filename_logger, setup_logger_formatter, show_warning, websocket_config, websocket_server_config

Methods included from InternalHelper

check_file, config_file, create_log_file, custom_commands, 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_capfile

Constructor Details

#initialize(manager, job_manager) ⇒ TerminalTable

Returns a new instance of TerminalTable.



14
15
16
17
18
19
20
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 14

def initialize(manager, job_manager)
  @manager = manager
  @job_manager = job_manager
  async.run
rescue => ex
  rescue_exception(ex)
end

Class Method Details

.topic ⇒ Object



10
11
12
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 10

def self.topic
  'sshkit_terminal'
end

Instance Method Details

#default_heaadings ⇒ Object



22
23
24
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 22

def default_heaadings
  ['Job ID', 'Job UUID', 'App/Stage', 'Action', 'ENV Variables', 'Current Task']
end

#display_table_on_terminal(table) ⇒ Object



42
43
44
45
46
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 42

def display_table_on_terminal(table)
  terminal_clear
  puts "\n#{table}\n"
  signal_complete
end

#managers_alive? ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 62

def managers_alive?
  @job_manager.alive? && @manager.alive?
end

#notify_time_change(_channel, _message) ⇒ Object



30
31
32
33
34
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 30

def notify_time_change(_channel, _message)
  table = Terminal::Table.new(title: 'Deployment Status Table', headings: default_heaadings)
  setup_table_jobs(table)
  display_table_on_terminal(table)
end

#rescue_exception(ex) ⇒ Object



36
37
38
39
40
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 36

def rescue_exception(ex)
  log_to_file("Terminal Table client disconnected due to error #{ex.inspect}")
  log_error(ex, 'stderr')
  terminate
end

#run ⇒ Object



26
27
28
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 26

def run
  subscribe(CapistranoMulticonfigParallel::TerminalTable.topic, :notify_time_change)
end

#setup_table_jobs(table) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 48

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
  end
end

#show_confirmation(message, default) ⇒ Object



56
57
58
59
60
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 56

def show_confirmation(message, default)
  exclusive do
    ask_confirm(message, default)
  end
end

#signal_complete ⇒ Object



66
67
68
69
70
71
72
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 66

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

#terminal_clear ⇒ Object



74
75
76
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 74

def terminal_clear
  system('cls') || system('clear') || puts("\e[H\e[2J")
end