Class: CapistranoMulticonfigParallel::TerminalTable
- Inherits:
-
Object
- Object
- CapistranoMulticonfigParallel::TerminalTable
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
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
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_output_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
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, options = {}) ⇒ TerminalTable
Returns a new instance of TerminalTable.
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 17
def initialize(manager, job_manager, options = {})
@manager = manager
@position = nil
@errors = []
@options = options.is_a?(Hash) ? options.stringify_keys : options
@job_manager = job_manager
async.run
rescue => ex
rescue_exception(ex)
end
|
Instance Attribute Details
#errors ⇒ Object
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
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
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
Returns the value of attribute options.
11
12
13
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 11
def options
@options
end
|
#position ⇒ Object
Returns the value of attribute position.
11
12
13
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 11
def position
@position
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
28
29
30
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 28
def default_heaadings
['Job ID', 'Job UUID', 'App/Stage', 'Action', 'ENV Variables', 'Current Task']
end
|
#display_table_on_terminal(table) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 57
def display_table_on_terminal(table)
cursor_position = fetch_cursor_position
CapistranoMulticonfigParallel::Cursor.display_on_screen("\n#{table}\n", @options.merge(position: @position))
puts(@errors.join("\n")) if @errors.present? && @options.fetch('clear_screen', false).to_s == 'false'
signal_complete
end
|
#fetch_cursor_position ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 48
def fetch_cursor_position
terminal_size = CapistranoMulticonfigParallel::Cursor.fetch_terminal_size
@position ||= CapistranoMulticonfigParallel::Cursor.fetch_position
return @position if terminal_size[:rows].nonzero? && position[:row] < (terminal_size[:rows] / 2)
CapistranoMulticonfigParallel::Cursor.move_to_home!(0,0)
@position = CapistranoMulticonfigParallel::Cursor.fetch_position
@position
end
|
#managers_alive? ⇒ Boolean
78
79
80
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 78
def managers_alive?
@job_manager.alive? && @manager.alive?
end
|
#notify_time_change(_channel, _message) ⇒ Object
36
37
38
39
40
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 36
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
42
43
44
45
46
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 42
def rescue_exception(ex)
log_to_file("Terminal Table client disconnected due to error #{ex.inspect}")
log_error(ex, 'stderr')
terminate
end
|
#run ⇒ Object
32
33
34
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 32
def run
subscribe(CapistranoMulticonfigParallel::TerminalTable.topic, :notify_time_change)
end
|
#setup_table_jobs(table) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 64
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
72
73
74
75
76
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 72
def show_confirmation(message, default)
exclusive do
ask_confirm(message, default)
end
end
|
#signal_complete ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb', line 82
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
|