class CapistranoMulticonfigParallel::TerminalTable

class used to display the progress of each worker on terminal screen using a table

Attributes

errors[R]
job_manager[R]
manager[R]
options[R]
position[R]
screen_erased[R]
terminal_rows[R]

Public Class Methods

new(manager, job_manager, options = {}) click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb, line 18
def initialize(manager, job_manager, options = {})
  @manager = manager
  @position = nil
  @terminal_rows = nil
  @cursor = CapistranoMulticonfigParallel::Cursor.new
  @errors = []
  @notifications = 0
  @options = options.is_a?(Hash) ? options.stringify_keys : options
  @job_manager = job_manager
  @screen_erased = false
  async.run
rescue => ex
  puts ex.inspect
  rescue_exception(ex)
end
topic() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb, line 14
def self.topic
  'sshkit_terminal'
end

Public Instance Methods

default_heaadings() click to toggle source
# 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) click to toggle source
# 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}",
  @options.merge(
  position: @position,
  table_size: table_size,
  screen_erased: @screen_erased
  )
  )
  print_errors
end
fetch_table_size(jobs) click to toggle source
# 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?() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb, line 95
def managers_alive?
  @manager.alive?
end
notify_time_change(_channel, message) click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb, line 42
def notify_time_change(_channel, message)
  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() click to toggle source
rescue_exception(ex) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb, line 89
def show_confirmation(message, default)
  exclusive do
    ask_confirm(message, default)
  end
end
signal_complete() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb, line 99
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