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.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/enviroblyd/command.rb', line 12 def initialize() params = @url = params.fetch "url" @script = decode_and_decompress 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/enviroblyd/command.rb', line 28 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
24 25 26 |
# File 'lib/enviroblyd/command.rb', line 24 def valid? @valid end |