Class: Ruboty::ExecCommand::Actions::Command
- Inherits:
-
Actions::Base
- Object
- Actions::Base
- Ruboty::ExecCommand::Actions::Command
- Defined in:
- lib/ruboty/exec_command/actions/command.rb
Instance Method Summary collapse
- #call ⇒ Object
- #command_body ⇒ Object
- #command_slot ⇒ Object
- #kill_command ⇒ Object
- #list_commands ⇒ Object
- #robot_prefix_pattern ⇒ Object
- #run_and_monitor(comm) ⇒ Object
Instance Method Details
#call ⇒ Object
5 6 7 8 9 |
# File 'lib/ruboty/exec_command/actions/command.rb', line 5 def call # TODO: add timeout c = Ruboty::ExecCommand::Command.new(command_args: command_body) run_and_monitor(c) end |
#command_body ⇒ Object
60 61 62 |
# File 'lib/ruboty/exec_command/actions/command.rb', line 60 def command_body .body.sub(robot_prefix_pattern,'') end |
#command_slot ⇒ Object
11 12 13 |
# File 'lib/ruboty/exec_command/actions/command.rb', line 11 def command_slot .robot.brain.data[:command_slot] ||= Ruboty::ExecCommand::CommandSlot.new end |
#kill_command ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/ruboty/exec_command/actions/command.rb', line 19 def kill_command # TODO: command list lock # kill running process, command is "kill command <index>" killed = command_slot.kill(.body.split.last.to_i) if killed.nil? .reply("Command [#{message.body.split.last}] not found.") end end |
#list_commands ⇒ Object
15 16 17 |
# File 'lib/ruboty/exec_command/actions/command.rb', line 15 def list_commands .reply(command_slot.list_commands) end |
#robot_prefix_pattern ⇒ Object
56 57 58 |
# File 'lib/ruboty/exec_command/actions/command.rb', line 56 def robot_prefix_pattern Ruboty::Action.prefix_pattern(.original[:robot].name) end |
#run_and_monitor(comm) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ruboty/exec_command/actions/command.rb', line 29 def run_and_monitor(comm) pid = command_slot.run(comm) .reply("[#{comm.command_name}] invoked.") # Waiter thread thread = Thread.new do ignore_pid, status = Process.wait2(pid) command_slot.forget(pid) if status.exitstatus == 0 .reply("[#{comm.command_name}] completed successfully.") .reply(comm.stdout_log.chomp) elsif status.signaled? .reply("[#{comm.command_name}] killed by signal #{status.termsig}") else .reply("[#{comm.command_name}] exit status with #{status}\n" + comm.stdout_log + "stderr: " + comm.stderr_log.chomp ) end end if ENV['RUBOTY_ENV'] == 'blocked_test' thread.join end end |