Class: Philiprehberger::TaskRunner::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/task_runner/result.rb

Overview

Represents the result of a shell command execution.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout:, stderr:, exit_code:, duration:, signal: nil) ⇒ Result

Returns a new instance of Result.

Parameters:

  • stdout (String)
  • stderr (String)
  • exit_code (Integer)
  • duration (Float)
  • signal (Symbol, nil) (defaults to: nil)


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

#durationFloat (readonly)

Returns execution duration in seconds.

Returns:

  • (Float)

    execution duration in seconds



17
18
19
# File 'lib/philiprehberger/task_runner/result.rb', line 17

def duration
  @duration
end

#exit_codeInteger (readonly)

Returns process exit code.

Returns:

  • (Integer)

    process exit code



14
15
16
# File 'lib/philiprehberger/task_runner/result.rb', line 14

def exit_code
  @exit_code
end

#signalSymbol? (readonly)

Returns signal that killed the process (:TERM, :KILL, or nil).

Returns:

  • (Symbol, nil)

    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

#stderrString (readonly)

Returns standard error.

Returns:

  • (String)

    standard error



11
12
13
# File 'lib/philiprehberger/task_runner/result.rb', line 11

def stderr
  @stderr
end

#stdoutString (readonly)

Returns standard output.

Returns:

  • (String)

    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?.

Returns:

  • (Boolean)


46
47
48
# File 'lib/philiprehberger/task_runner/result.rb', line 46

def failure?
  !success?
end

#success?Boolean

Whether the command exited successfully.

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


54
55
56
# File 'lib/philiprehberger/task_runner/result.rb', line 54

def timed_out?
  %i[TERM KILL].include?(@signal)
end

#to_hHash

Hash representation of the result.

Returns:

  • (Hash)


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