Class: Enviroblyd::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/enviroblyd/command.rb

Constant Summary collapse

DEFAULT_TIMEOUT_SECONDS =
5 * 60
DEFAULT_RUNTIME =
"/bin/bash"

Instance Method Summary collapse

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(message)
  params = parse_message message
  @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

#runObject



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

Returns:

  • (Boolean)


24
25
26
# File 'lib/enviroblyd/command.rb', line 24

def valid?
  @valid
end