philiprehberger-task_runner 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +20 -0
- data/lib/philiprehberger/task_runner/result.rb +31 -0
- data/lib/philiprehberger/task_runner/version.rb +1 -1
- data/lib/philiprehberger/task_runner.rb +25 -0
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0edebc1ac881ac5547d09cc825898875461f22b5b13edd6c5c01b3efc9d7a13f
|
|
4
|
+
data.tar.gz: f7172ad5068e86cb31fa0cb48f1eac41b21f239ff884f9333f52b52d33df29bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 96f98887b963b6e19cd0025b1d2621571422b21ec7c7e72f936892b4f768b0f023590da3591b575deaf8b6395c8d5b27fe3a6ff56bb0a057159f594383323a40
|
|
7
|
+
data.tar.gz: 84271258a850cc7dbb6a3bda26db60c55b7a43b61b9323659eec0ecbe4bc83f1bfe804ade2b33922de9643418becdc8f595231fa9cf84e9663e57b85ca1a8e15
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - 2026-04-20
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Result#failure?` — logical inverse of `#success?` for clearer branching
|
|
14
|
+
- `Result#timed_out?` — true when the process was killed by the task runner for exceeding its timeout (`:TERM` or `:KILL` signal)
|
|
15
|
+
- `:timed_out` key added to `Result#to_h` alongside the existing `:success` flag
|
|
16
|
+
|
|
17
|
+
## [0.3.0] - 2026-04-09
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- `TaskRunner.run!` raises `CommandError` on non-zero exit code (same API as `run`)
|
|
21
|
+
- `CommandError#result` exposes the full `Result` object for inspection
|
|
22
|
+
- `Result#to_h` for hash serialization of command results
|
|
23
|
+
|
|
10
24
|
## [0.2.1] - 2026-03-31
|
|
11
25
|
|
|
12
26
|
### Changed
|
data/README.md
CHANGED
|
@@ -36,6 +36,21 @@ puts result.success? # => true
|
|
|
36
36
|
puts result.duration # => 0.012
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
### Raising on Failure
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
# Raises CommandError if the command exits non-zero
|
|
43
|
+
result = Philiprehberger::TaskRunner.run!('make', 'build')
|
|
44
|
+
|
|
45
|
+
# The error includes the full Result for inspection
|
|
46
|
+
begin
|
|
47
|
+
Philiprehberger::TaskRunner.run!('false')
|
|
48
|
+
rescue Philiprehberger::TaskRunner::CommandError => e
|
|
49
|
+
puts e.message # => "command exited with code 1"
|
|
50
|
+
puts e.result.stderr # => captured stderr
|
|
51
|
+
end
|
|
52
|
+
```
|
|
53
|
+
|
|
39
54
|
### Timeout
|
|
40
55
|
|
|
41
56
|
```ruby
|
|
@@ -99,14 +114,19 @@ end
|
|
|
99
114
|
| Method / Class | Description |
|
|
100
115
|
|----------------|-------------|
|
|
101
116
|
| `.run(cmd, *args, timeout:, env:, chdir:, signal:, kill_after:, stdin:)` | Run a command and return a Result |
|
|
117
|
+
| `.run!(cmd, *args, **opts)` | Same as `run`, raises `CommandError` on non-zero exit |
|
|
118
|
+
| `CommandError#result` | The failed `Result` object |
|
|
102
119
|
| `.run(cmd) { \|line\| ... }` | Run with line-by-line stdout streaming |
|
|
103
120
|
| `.run(cmd) { \|line, stream\| ... }` | Run with stdout and stderr streaming |
|
|
104
121
|
| `Result#stdout` | Captured standard output |
|
|
105
122
|
| `Result#stderr` | Captured standard error |
|
|
106
123
|
| `Result#exit_code` | Process exit code |
|
|
107
124
|
| `Result#success?` | Whether exit code is 0 |
|
|
125
|
+
| `Result#failure?` | Logical inverse of `#success?` |
|
|
108
126
|
| `Result#duration` | Execution time in seconds |
|
|
109
127
|
| `Result#signal` | Signal that killed the process (:TERM, :KILL, or nil) |
|
|
128
|
+
| `Result#timed_out?` | Whether the process was killed for exceeding its timeout |
|
|
129
|
+
| `Result#to_h` | Hash representation of the result (includes `:success` and `:timed_out`) |
|
|
110
130
|
|
|
111
131
|
## Development
|
|
112
132
|
|
|
@@ -38,6 +38,37 @@ module Philiprehberger
|
|
|
38
38
|
def success?
|
|
39
39
|
@exit_code.zero?
|
|
40
40
|
end
|
|
41
|
+
|
|
42
|
+
# Whether the command exited with a non-zero status, was killed by a
|
|
43
|
+
# signal, or timed out. The logical inverse of {#success?}.
|
|
44
|
+
#
|
|
45
|
+
# @return [Boolean]
|
|
46
|
+
def failure?
|
|
47
|
+
!success?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Whether the command was terminated by the task runner because it
|
|
51
|
+
# exceeded its timeout (SIGTERM or SIGKILL).
|
|
52
|
+
#
|
|
53
|
+
# @return [Boolean]
|
|
54
|
+
def timed_out?
|
|
55
|
+
%i[TERM KILL].include?(@signal)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Hash representation of the result.
|
|
59
|
+
#
|
|
60
|
+
# @return [Hash]
|
|
61
|
+
def to_h
|
|
62
|
+
{
|
|
63
|
+
stdout: @stdout,
|
|
64
|
+
stderr: @stderr,
|
|
65
|
+
exit_code: @exit_code,
|
|
66
|
+
duration: @duration,
|
|
67
|
+
signal: @signal,
|
|
68
|
+
success: success?,
|
|
69
|
+
timed_out: timed_out?
|
|
70
|
+
}
|
|
71
|
+
end
|
|
41
72
|
end
|
|
42
73
|
end
|
|
43
74
|
end
|
|
@@ -11,6 +11,17 @@ module Philiprehberger
|
|
|
11
11
|
class Error < StandardError; end
|
|
12
12
|
class TimeoutError < Error; end
|
|
13
13
|
|
|
14
|
+
# Raised by run! when the command exits with a non-zero status.
|
|
15
|
+
class CommandError < Error
|
|
16
|
+
# @return [Result] the failed command result
|
|
17
|
+
attr_reader :result
|
|
18
|
+
|
|
19
|
+
def initialize(result)
|
|
20
|
+
@result = result
|
|
21
|
+
super("command exited with code #{result.exit_code}")
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
14
25
|
# Run a shell command with output capture, optional timeout, streaming, signal handling, and stdin piping.
|
|
15
26
|
#
|
|
16
27
|
# When a block is given, each line of stdout/stderr is yielded as it arrives.
|
|
@@ -45,6 +56,20 @@ module Philiprehberger
|
|
|
45
56
|
end
|
|
46
57
|
end
|
|
47
58
|
|
|
59
|
+
# Run a shell command, raising CommandError on non-zero exit.
|
|
60
|
+
#
|
|
61
|
+
# Accepts the same arguments as {.run}.
|
|
62
|
+
#
|
|
63
|
+
# @return [Result] the command result
|
|
64
|
+
# @raise [CommandError] if the command exits with a non-zero status
|
|
65
|
+
# @raise [TimeoutError] if the command exceeds the timeout
|
|
66
|
+
def self.run!(cmd, ...)
|
|
67
|
+
result = run(cmd, ...)
|
|
68
|
+
raise CommandError, result unless result.success?
|
|
69
|
+
|
|
70
|
+
result
|
|
71
|
+
end
|
|
72
|
+
|
|
48
73
|
# @api private
|
|
49
74
|
def self.run_capture(env_hash, full_cmd, spawn_opts, timeout, start_time, signal, kill_after, stdin_data)
|
|
50
75
|
stdout_buf = +''
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-task_runner
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-04-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Run shell commands with captured stdout/stderr, exit code, duration measurement,
|
|
14
14
|
configurable timeout, environment variables, line-by-line streaming, graceful signal
|
|
@@ -25,11 +25,11 @@ files:
|
|
|
25
25
|
- lib/philiprehberger/task_runner.rb
|
|
26
26
|
- lib/philiprehberger/task_runner/result.rb
|
|
27
27
|
- lib/philiprehberger/task_runner/version.rb
|
|
28
|
-
homepage: https://
|
|
28
|
+
homepage: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-task_runner
|
|
29
29
|
licenses:
|
|
30
30
|
- MIT
|
|
31
31
|
metadata:
|
|
32
|
-
homepage_uri: https://
|
|
32
|
+
homepage_uri: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-task_runner
|
|
33
33
|
source_code_uri: https://github.com/philiprehberger/rb-task-runner
|
|
34
34
|
changelog_uri: https://github.com/philiprehberger/rb-task-runner/blob/main/CHANGELOG.md
|
|
35
35
|
bug_tracker_uri: https://github.com/philiprehberger/rb-task-runner/issues
|