class Ruboty::ExecCommand::CommandSlot
Public Class Methods
new()
click to toggle source
# File lib/ruboty/exec_command/command_slot.rb, line 5 def initialize @commands = [] end
Public Instance Methods
command_in_list(idx_or_pid)
click to toggle source
# File lib/ruboty/exec_command/command_slot.rb, line 27 def command_in_list(idx_or_pid) found = @commands.index { |c| c.pid == idx_or_pid } if found.nil? # look for the command with index i = idx_or_pid.to_i if i <= 0 or i > @commands.size nil else @commands[i-1] end else @commands[found] end end
forget(pid)
click to toggle source
# File lib/ruboty/exec_command/command_slot.rb, line 20 def forget(pid) # remove thread object @commands.delete_if do |c| c.pid == pid end end
kill(idx_or_pid)
click to toggle source
# File lib/ruboty/exec_command/command_slot.rb, line 58 def kill(idx_or_pid) command = command_in_list(idx_or_pid) unless command.nil? Process.kill(-9, command.pid) # kill process group forget(command.pid) else false end end
list_commands()
click to toggle source
# File lib/ruboty/exec_command/command_slot.rb, line 48 def list_commands if @commands.size == 0 "No command running." else @commands.map.with_index do |c, number| "#{number+1}: #{c.command_name} (PID[#{c.pid}], started at #{c.start_at})\n" end.join.chomp end end
remember(comm)
click to toggle source
# File lib/ruboty/exec_command/command_slot.rb, line 13 def remember(comm) # remember # comm: command object # TODO: add owner info @commands << comm end
run(command)
click to toggle source
# File lib/ruboty/exec_command/command_slot.rb, line 43 def run(command) remember(command) command.run_bg(command.opt_args) end
running_commands()
click to toggle source
# File lib/ruboty/exec_command/command_slot.rb, line 9 def running_commands @commands end