Class: ProcessExecuter::Commands::SpawnWithTimeout Private
- Inherits:
-
Object
- Object
- ProcessExecuter::Commands::SpawnWithTimeout
- Defined in:
- lib/process_executer/commands/spawn_with_timeout.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Spawns a subprocess, waits until it completes, and returns the result
Wraps Process.spawn
to provide the core functionality for
ProcessExecuter.spawn_with_timeout.
It accepts all Process.spawn execution
options
plus the additional option timeout_after
.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#command ⇒ Array<String>
readonly
private
The command to be run in the subprocess.
-
#elapsed_time ⇒ Numeric
readonly
private
The elapsed time in seconds that the command ran.
-
#options ⇒ ProcessExecuter::Options::SpawnWithTimeoutOptions
readonly
private
The options that were used to spawn the process.
-
#pid ⇒ Integer
readonly
private
The process ID of the spawned subprocess.
-
#result ⇒ ProcessExecuter::Result
readonly
private
The result of the completed subprocess.
-
#status ⇒ Process::Status
readonly
private
The status returned by Process.wait2.
-
#timed_out ⇒ Boolean
(also: #timed_out?)
readonly
private
Whether the process timed out.
Instance Method Summary collapse
-
#call ⇒ ProcessExecuter::Result
private
Run a command and return the result.
-
#initialize(command, options) ⇒ SpawnWithTimeout
constructor
private
Create a new SpawnWithTimeout instance.
Constructor Details
#initialize(command, options) ⇒ SpawnWithTimeout
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new SpawnWithTimeout instance
30 31 32 33 |
# File 'lib/process_executer/commands/spawn_with_timeout.rb', line 30 def initialize(command, ) @command = command @options = end |
Instance Attribute Details
#command ⇒ Array<String> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The command to be run in the subprocess
64 65 66 |
# File 'lib/process_executer/commands/spawn_with_timeout.rb', line 64 def command @command end |
#elapsed_time ⇒ Numeric (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The elapsed time in seconds that the command ran
108 109 110 |
# File 'lib/process_executer/commands/spawn_with_timeout.rb', line 108 def elapsed_time @elapsed_time end |
#options ⇒ ProcessExecuter::Options::SpawnWithTimeoutOptions (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The options that were used to spawn the process
70 71 72 |
# File 'lib/process_executer/commands/spawn_with_timeout.rb', line 70 def @options end |
#pid ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The process ID of the spawned subprocess
79 80 81 |
# File 'lib/process_executer/commands/spawn_with_timeout.rb', line 79 def pid @pid end |
#result ⇒ ProcessExecuter::Result (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The result of the completed subprocess
117 118 119 |
# File 'lib/process_executer/commands/spawn_with_timeout.rb', line 117 def result @result end |
#status ⇒ Process::Status (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The status returned by Process.wait2
88 89 90 |
# File 'lib/process_executer/commands/spawn_with_timeout.rb', line 88 def status @status end |
#timed_out ⇒ Boolean (readonly) Also known as: timed_out?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether the process timed out
97 98 99 |
# File 'lib/process_executer/commands/spawn_with_timeout.rb', line 97 def timed_out @timed_out end |
Instance Method Details
#call ⇒ ProcessExecuter::Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run a command and return the result
49 50 51 52 53 54 55 56 57 |
# File 'lib/process_executer/commands/spawn_with_timeout.rb', line 49 def call begin @pid = Process.spawn(*command, **.) rescue StandardError => e raise ProcessExecuter::SpawnError, "Failed to spawn process: #{e.}" end wait_for_process end |