Sha256: b59a870fafb7cb17f0b9857de4113d1ec7060fc579543a1eb3d267b4dbad128e

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

require_relative '../helpers/application_helper'
module CapistranoMulticonfigParallel
  # class used to display the progress of each worker on terminal screen using a table
  class TerminalTable
    include Celluloid
    include Celluloid::Notifications
    include Celluloid::Logger
    include CapistranoMulticonfigParallel::ApplicationHelper
    def self.topic
      'sshkit_terminal'
    end

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

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

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

    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

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

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

    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

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

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

    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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
capistrano_multiconfig_parallel-0.27.2 lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb
capistrano_multiconfig_parallel-0.27.0 lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb
capistrano_multiconfig_parallel-0.26.0 lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb
capistrano_multiconfig_parallel-0.25.1 lib/capistrano_multiconfig_parallel/celluloid/terminal_table.rb