Sha256: cf2cacf60f84294349a5d9173bed30f0bf917d59904d3f793ff650848c6495f9

Contents?: true

Size: 1.66 KB

Versions: 21

Compression:

Stored size: 1.66 KB

Contents

module Vedeu

  # @example
  #   Vedeu::TestApplication.build
  class Subprocess

    # @param (see #initialize)
    def self.execute!(application)
      new(application).execute!
    end

    # Returns a new instance of Vedeu::Subprocess.
    #
    # @param application [Vedeu::TestApplication]
    # @return [Vedeu::Subprocess]
    def initialize(application)
      @application = application
      @pid         = nil
    end

    # :nocov:
    # @return [Array]
    def execute!
      file_open && file_write && file_close

      @pid = fork do
        exec(file_path)
      end

      Process.detach(@pid)

      self
    end
    # :nocov:

    # Sends the KILL signal to the process.
    #
    # @return [void]
    def kill
      Process.kill('KILL', pid)

      file_unlink
    end

    protected

    # @!attribute [r] application
    # @return [Vedeu::TestApplication]
    attr_reader :application

    # @!attribute [rw] pid
    # @return [Fixnum]
    attr_accessor :pid

    private

    # @return [String]
    def command
      "ruby #{file_path}"
    end

    # @return [Fixnum] The number of bytes written.
    def file_write
      file.write(application)
    end

    # @return [NilClass]
    def file_close
      file.close
    end

    # @return [Fixnum] The number of files removed; 1.
    def file_unlink
      File.unlink("/tmp/foo_#{timestamp}")
    end

    # return [String]
    def file_path
      file.path
    end

    # @return [File]
    def file_open
      @file ||= File.new("/tmp/foo_#{timestamp}", 'w', 0755)
    end
    alias_method :file, :file_open

    # return [Fixnum]
    def timestamp
      @timestamp ||= Time.now.to_i
    end

  end # Subprocess

end # Vedeu

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
vedeu-0.4.39 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.38 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.37 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.36 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.35 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.34 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.33 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.32 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.31 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.30 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.29 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.28 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.27 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.26 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.25 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.24 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.23 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.22 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.21 lib/vedeu/distributed/subprocess.rb
vedeu-0.4.20 lib/vedeu/distributed/subprocess.rb