class Spool::Spawner
Attributes
configuration[R]
Public Class Methods
new(configuration)
click to toggle source
# File lib/spool/spawner.rb, line 6 def initialize(configuration) @configuration = configuration end
spawn(configuration)
click to toggle source
# File lib/spool/spawner.rb, line 31 def self.spawn(configuration) new(configuration).spawn end
Public Instance Methods
spawn()
click to toggle source
# File lib/spool/spawner.rb, line 10 def spawn base_file = File.join Dir.tmpdir, SecureRandom.uuid out_file = "#{base_file}.out" command = configuration.command.strip pid = Process.spawn configuration.env, "exec #{command}", chdir: configuration.dir, out: out_file, err: out_file Process.detach pid Datacenter::Process.new(pid).tap do |process| raise "Invalid command: #{command}\n#{IO.read(out_file)}" unless process.alive? end ensure File.delete out_file if File.exist? out_file end