Class: Philiprehberger::TaskRunner::Result
- Inherits:
-
Object
- Object
- Philiprehberger::TaskRunner::Result
- Defined in:
- lib/philiprehberger/task_runner/result.rb
Overview
Represents the result of a shell command execution.
Instance Attribute Summary collapse
-
#duration ⇒ Float
readonly
Execution duration in seconds.
-
#exit_code ⇒ Integer
readonly
Process exit code.
-
#signal ⇒ Symbol?
readonly
Signal that killed the process (:TERM, :KILL, or nil).
-
#stderr ⇒ String
readonly
Standard error.
-
#stdout ⇒ String
readonly
Standard output.
Instance Method Summary collapse
-
#failure? ⇒ Boolean
Whether the command exited with a non-zero status, was killed by a signal, or timed out.
-
#initialize(stdout:, stderr:, exit_code:, duration:, signal: nil) ⇒ Result
constructor
A new instance of Result.
-
#success? ⇒ Boolean
Whether the command exited successfully.
-
#timed_out? ⇒ Boolean
Whether the command was terminated by the task runner because it exceeded its timeout (SIGTERM or SIGKILL).
-
#to_h ⇒ Hash
Hash representation of the result.
Constructor Details
#initialize(stdout:, stderr:, exit_code:, duration:, signal: nil) ⇒ Result
Returns a new instance of Result.
27 28 29 30 31 32 33 |
# File 'lib/philiprehberger/task_runner/result.rb', line 27 def initialize(stdout:, stderr:, exit_code:, duration:, signal: nil) @stdout = stdout @stderr = stderr @exit_code = exit_code @duration = duration @signal = signal end |
Instance Attribute Details
#duration ⇒ Float (readonly)
Returns execution duration in seconds.
17 18 19 |
# File 'lib/philiprehberger/task_runner/result.rb', line 17 def duration @duration end |
#exit_code ⇒ Integer (readonly)
Returns process exit code.
14 15 16 |
# File 'lib/philiprehberger/task_runner/result.rb', line 14 def exit_code @exit_code end |
#signal ⇒ Symbol? (readonly)
Returns signal that killed the process (:TERM, :KILL, or nil).
20 21 22 |
# File 'lib/philiprehberger/task_runner/result.rb', line 20 def signal @signal end |
#stderr ⇒ String (readonly)
Returns standard error.
11 12 13 |
# File 'lib/philiprehberger/task_runner/result.rb', line 11 def stderr @stderr end |
#stdout ⇒ String (readonly)
Returns standard output.
8 9 10 |
# File 'lib/philiprehberger/task_runner/result.rb', line 8 def stdout @stdout end |
Instance Method Details
#failure? ⇒ Boolean
Whether the command exited with a non-zero status, was killed by a signal, or timed out. The logical inverse of #success?.
46 47 48 |
# File 'lib/philiprehberger/task_runner/result.rb', line 46 def failure? !success? end |
#success? ⇒ Boolean
Whether the command exited successfully.
38 39 40 |
# File 'lib/philiprehberger/task_runner/result.rb', line 38 def success? @exit_code.zero? end |
#timed_out? ⇒ Boolean
Whether the command was terminated by the task runner because it exceeded its timeout (SIGTERM or SIGKILL).
54 55 56 |
# File 'lib/philiprehberger/task_runner/result.rb', line 54 def timed_out? %i[TERM KILL].include?(@signal) end |
#to_h ⇒ Hash
Hash representation of the result.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/philiprehberger/task_runner/result.rb', line 61 def to_h { stdout: @stdout, stderr: @stderr, exit_code: @exit_code, duration: @duration, signal: @signal, success: success?, timed_out: timed_out? } end |