Class: ProcessExecuter::Result
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ProcessExecuter::Result
- Defined in:
- lib/process_executer/result.rb
Overview
A decorator for Process::Status that adds the following attributes:
command: the command that was used to spawn the processoptions: the options that were used to spawn the processelapsed_time: the seconds the command rantimed_out?: true if the process timed out
In the rare case that the timeout fires after the process was already
reaped, its status is lost: the result delegates to a nil status and
timed_out? is true. #success? and #to_s still work, but methods
forwarded to the status (like exitstatus or signaled?) will raise
NoMethodError.
Instance Attribute Summary collapse
-
#command ⇒ Array
readonly
The command that was used to spawn the process.
-
#elapsed_time ⇒ Numeric
readonly
The seconds the command ran.
-
#options ⇒ ProcessExecuter::Options::Base
readonly
The options that were used to spawn the process.
-
#timed_out ⇒ Boolean
(also: #timed_out?)
readonly
True if the wait for the process was cut short by
timeout_afterelapsing.
Instance Method Summary collapse
-
#initialize(status, command:, options:, timed_out:, elapsed_time:) ⇒ Result
constructor
Create a new Result object.
-
#success? ⇒ true, ...
Overrides the default
success?method to returnnilif the process timed out. -
#to_s ⇒ String
Return a string representation of the result.
Constructor Details
#initialize(status, command:, options:, timed_out:, elapsed_time:) ⇒ Result
Create a new Result object
45 46 47 48 49 50 51 |
# File 'lib/process_executer/result.rb', line 45 def initialize(status, command:, options:, timed_out:, elapsed_time:) super(status) @command = command @options = @timed_out = timed_out @elapsed_time = elapsed_time end |
Instance Attribute Details
#command ⇒ Array (readonly)
The command that was used to spawn the process
58 59 60 |
# File 'lib/process_executer/result.rb', line 58 def command @command end |
#elapsed_time ⇒ Numeric (readonly)
The seconds the command ran
77 78 79 |
# File 'lib/process_executer/result.rb', line 77 def elapsed_time @elapsed_time end |
#options ⇒ ProcessExecuter::Options::Base (readonly)
The options that were used to spawn the process
71 72 73 |
# File 'lib/process_executer/result.rb', line 71 def @options end |
#timed_out ⇒ Boolean (readonly) Also known as: timed_out?
True if the wait for the process was cut short by timeout_after elapsing
A timed out process is sent the SIGKILL signal, unless it had already exited in the moment between the timeout firing and the kill (the raced-timeout corner case described above).
90 91 92 |
# File 'lib/process_executer/result.rb', line 90 def timed_out @timed_out end |
Instance Method Details
#success? ⇒ true, ...
Overrides the default success? method to return nil if the process timed out
This is because when a timeout occurs, Windows will still return true.
102 103 104 105 106 |
# File 'lib/process_executer/result.rb', line 102 def success? return nil if timed_out? # rubocop:disable Style/ReturnNilInPredicateMethodDefinition super end |
#to_s ⇒ String
Return a string representation of the result
115 116 117 |
# File 'lib/process_executer/result.rb', line 115 def to_s "#{super}#{" timed out after #{.timeout_after}s" if timed_out?}" end |