Class: Aruba::Processes::BasicProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/processes/basic_process.rb

Overview

Basic Process

‘BasicProcess` is not meant for direct use - `BasicProcess.new` - by users.

Direct Known Subclasses

DebugProcess, InProcess, SpawnProcess

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, exit_timeout, io_wait_timeout, working_directory, environment = Aruba.platform.environment_variables.hash_from_env, main_class = nil, stop_signal = nil, startup_wait_time = 0) ⇒ BasicProcess

rubocop:disable Metrics/ParameterLists



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/aruba/processes/basic_process.rb', line 17

def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, # rubocop:disable Metrics/ParameterLists
               environment = Aruba.platform.environment_variables.hash_from_env,
               main_class = nil, stop_signal = nil, startup_wait_time = 0)
  @cmd               = cmd
  @working_directory = working_directory
  @environment       = environment
  @main_class        = main_class
  @exit_status       = nil
  @stop_signal       = stop_signal
  @startup_wait_time = startup_wait_time

  @exit_timeout    = exit_timeout
  @io_wait_timeout = io_wait_timeout

  @started         = false
  @timed_out       = false
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



14
15
16
# File 'lib/aruba/processes/basic_process.rb', line 14

def environment
  @environment
end

#exit_statusObject (readonly)

Returns the value of attribute exit_status.



14
15
16
# File 'lib/aruba/processes/basic_process.rb', line 14

def exit_status
  @exit_status
end

#exit_timeoutObject (readonly)

Returns the value of attribute exit_timeout.



14
15
16
# File 'lib/aruba/processes/basic_process.rb', line 14

def exit_timeout
  @exit_timeout
end

#io_wait_timeoutObject (readonly)

Returns the value of attribute io_wait_timeout.



14
15
16
# File 'lib/aruba/processes/basic_process.rb', line 14

def io_wait_timeout
  @io_wait_timeout
end

#main_classObject (readonly)

Returns the value of attribute main_class.



14
15
16
# File 'lib/aruba/processes/basic_process.rb', line 14

def main_class
  @main_class
end

#startup_wait_timeObject (readonly)

Returns the value of attribute startup_wait_time.



14
15
16
# File 'lib/aruba/processes/basic_process.rb', line 14

def startup_wait_time
  @startup_wait_time
end

#stop_signalObject (readonly)

Returns the value of attribute stop_signal.



14
15
16
# File 'lib/aruba/processes/basic_process.rb', line 14

def stop_signal
  @stop_signal
end

#working_directoryObject (readonly)

Returns the value of attribute working_directory.



14
15
16
# File 'lib/aruba/processes/basic_process.rb', line 14

def working_directory
  @working_directory
end

Instance Method Details

#after_runObject

Hook which is run after command is run



111
# File 'lib/aruba/processes/basic_process.rb', line 111

def after_run; end

#argumentsObject



127
128
129
130
131
# File 'lib/aruba/processes/basic_process.rb', line 127

def arguments
  return Shellwords.split(commandline)[1..] if Shellwords.split(commandline).size > 1

  []
end

#before_runObject

Hook which is run before command is run



108
# File 'lib/aruba/processes/basic_process.rb', line 108

def before_run; end

#close_ioObject

Raises:

  • (NotImplementedError)


66
67
68
# File 'lib/aruba/processes/basic_process.rb', line 66

def close_io(*)
  raise NotImplementedError
end

#commandObject



123
124
125
# File 'lib/aruba/processes/basic_process.rb', line 123

def command
  Shellwords.split(commandline).first
end

#commandlineObject

Return command line



36
37
38
# File 'lib/aruba/processes/basic_process.rb', line 36

def commandline
  @cmd
end

#contentObject

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/aruba/processes/basic_process.rb', line 78

def content
  raise NotImplementedError
end

#empty?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/aruba/processes/basic_process.rb', line 133

def empty?
  false
end

#filesystem_statusObject

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/aruba/processes/basic_process.rb', line 74

def filesystem_status
  raise NotImplementedError
end

#inspectObject Also known as: to_s



113
114
115
116
117
118
119
# File 'lib/aruba/processes/basic_process.rb', line 113

def inspect
  out = truncate(stdout(wait_for_io: 0).inspect, 35)
  err = truncate(stderr(wait_for_io: 0).inspect, 35)

  fmt = '#<%s:%s commandline="%s": stdout=%s stderr=%s>'
  format fmt, self.class, object_id, commandline, out, err
end

#output(opts = {}) ⇒ Object

Output stderr and stdout



46
47
48
# File 'lib/aruba/processes/basic_process.rb', line 46

def output(opts = {})
  stdout(opts) + stderr(opts)
end

#pidObject

Output pid of process

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/aruba/processes/basic_process.rb', line 41

def pid
  raise NotImplementedError
end

#restartObject

Restart a command



87
88
89
90
# File 'lib/aruba/processes/basic_process.rb', line 87

def restart
  stop
  start
end

#send_signalObject

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/aruba/processes/basic_process.rb', line 70

def send_signal(*)
  raise NotImplementedError
end

#started?Boolean

Was process already started

Returns:

  • (Boolean)


98
99
100
# File 'lib/aruba/processes/basic_process.rb', line 98

def started?
  @started == true
end

#stderrObject

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/aruba/processes/basic_process.rb', line 62

def stderr(*)
  raise NotImplementedError
end

#stdinObject

Raises:

  • (NotImplementedError)


54
55
56
# File 'lib/aruba/processes/basic_process.rb', line 54

def stdin(*)
  raise NotImplementedError
end

#stdoutObject

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/aruba/processes/basic_process.rb', line 58

def stdout(*)
  raise NotImplementedError
end

#stopped?Boolean

Was process already stopped

Returns:

  • (Boolean)


93
94
95
# File 'lib/aruba/processes/basic_process.rb', line 93

def stopped?
  @started == false
end

#timed_out?Boolean

Does the process failed to stop in time

Returns:

  • (Boolean)


103
104
105
# File 'lib/aruba/processes/basic_process.rb', line 103

def timed_out?
  @timed_out == true
end

#waitObject

Raises:

  • (NotImplementedError)


82
83
84
# File 'lib/aruba/processes/basic_process.rb', line 82

def wait
  raise NotImplementedError
end

#writeObject

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/aruba/processes/basic_process.rb', line 50

def write(*)
  raise NotImplementedError
end