Class: Enviroblyd::Command
- Inherits:
-
Object
- Object
- Enviroblyd::Command
- Defined in:
- lib/enviroblyd/command.rb
Constant Summary collapse
- DEFAULT_TIMEOUT_SECONDS =
5 * 60
- DEFAULT_RUNTIME =
"/bin/bash"
Instance Method Summary collapse
-
#initialize(message) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(message) ⇒ Command
Returns a new instance of Command.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/enviroblyd/command.rb', line 10 def initialize() params = @url = params.fetch "url" @script = params.fetch "script" @runtime = params.fetch "runtime", DEFAULT_RUNTIME @timeout = params.fetch "timeout", DEFAULT_TIMEOUT_SECONDS @stdout = @stderr = @exit_code = nil @valid = true rescue NoMethodError, KeyError @valid = false end |
Instance Method Details
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/enviroblyd/command.rb', line 26 def run puts "Command #{@url} starting" Open3.popen3("timeout #{@timeout} #{@runtime}") do |stdin, stdout, stderr, thread| stdin.puts @script stdin.close @stdout = stdout.read @stderr = stderr.read @exit_code = thread.value.exitstatus end puts "Command #{@url} exited with #{@exit_code}" $stdout.flush Enviroblyd::Web.http(@url, type: Net::HTTP::Put, params: to_complete_params) end |
#valid? ⇒ Boolean
22 23 24 |
# File 'lib/enviroblyd/command.rb', line 22 def valid? @valid end |