Sha256: de1235c1e66296361208316c2824b933993e601b6b5e990a015f8dfaf2b8b696

Contents?: true

Size: 854 Bytes

Versions: 6

Compression:

Stored size: 854 Bytes

Contents

module Spool
  class Spawner

    attr_reader :configuration

    def initialize(configuration)
      @configuration = configuration
    end

    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

    def self.spawn(configuration)
      new(configuration).spawn
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spool-1.0.5 lib/spool/spawner.rb
spool-1.0.4 lib/spool/spawner.rb
spool-1.0.3 lib/spool/spawner.rb
spool-1.0.2 lib/spool/spawner.rb
spool-1.0.1 lib/spool/spawner.rb
spool-1.0.0 lib/spool/spawner.rb