module BioDSL::StatusHelper
Namespace with methods to record and manipulate cammand status.
Public Instance Methods
Given a list of symbols initialize all as status hash keys with the value 0.
@param status [Hash] Status hash. @param args [Array] List of symbols.
# File lib/BioDSL/helpers/status_helper.rb, line 39 def status_init(status, args) args.each { |arg| status[arg] = 0 } @status = status end
Track the status progress of a running command in a seperate thread and output the status at speficied intervals.
@param commands [Array] List of commands whos status should be output. @param block [Proc] Track the command in the given block.
@raise [RunTimeError] If no block is given.
# File lib/BioDSL/helpers/status_helper.rb, line 51 def status_progress(commands, &block) fail 'No block given' unless block thread = Thread.new do print "\e[H\e[2J" # Console code to clear screen loop do progress_print(commands) sleep BioDSL::Config::STATUS_PROGRESS_INTERVAL end end block.call thread.terminate progress_print(commands) end
Private Instance Methods
Print the progress table to terminal.
@param commands [Array] List of commands whos status should be output.
# File lib/BioDSL/helpers/status_helper.rb, line 76 def progress_print(commands) print "\e[1;1H" # Console code to move cursor to 1,1 coordinate. puts "Started: #{commands.first.status[:time_start]}" puts status_tabulate(commands) end
Compile rows with table data.
@param commands [Array] List of commands whos status should be output.
@return [Array] List of rows.
# File lib/BioDSL/helpers/status_helper.rb, line 105 def status_rows(commands) rows = [%w(name records_in records_out time_elapsed status)] commands.each do |command| update_time(command) row = [] row << command.name row << command.status[:records_in].commify row << command.status[:records_out].commify row << command.status[:time_elapsed] row << command.run_status rows << row end rows end
Create status table.
@param commands [Array] List of commands whos status should be output.
@return [String] Status table.
# File lib/BioDSL/helpers/status_helper.rb, line 87 def status_tabulate(commands) return unless commands.first.status[:records_in] table = Terminal::Table.new table.style = {border_x: '', border_y: '', border_i: ''} table.rows = status_rows(commands) table.align_column(1, :right) table.align_column(2, :right) table.to_s end
Update the time_stop and time_elapsed for a given command.
@param command [BioDSL::Command] Command
object.
# File lib/BioDSL/helpers/status_helper.rb, line 126 def update_time(command) command.status[:time_stop] = Time.now unless command.run_status == 'done' command.calc_time_elapsed end