philiprehberger-task_queue 0.2.8 → 0.3.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 +23 -0
- data/README.md +40 -3
- data/lib/philiprehberger/task_queue/queue.rb +14 -1
- data/lib/philiprehberger/task_queue/version.rb +1 -1
- data/lib/philiprehberger/task_queue/worker.rb +5 -3
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2524cd95e75d5fef01076f0bb4895a3d3aceeed233a2b68eabc596c7a731ebfa
|
|
4
|
+
data.tar.gz: 7df5392a5796de69bf086cc47484cb5481f1e131099d3994062e5e3c308d4b06
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 60adcdcd0b47caba95f1eb03c8be5e340e62aaf9fe2d9ed5ac85a702e1ac89d95e65c810a245bd5d9d0ddbd7fcbc68c493c46497a53298fe7721f90240107582
|
|
7
|
+
data.tar.gz: 1657f7b9c9b358a58ca2aae35896374e5193a295e753d47054f662233237fef68148175d8e7e40a050bf102fb68f32cf790827f79f84b9450fea7d0be75ab8ac
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-04-04
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `on_complete(&block)` callback that fires after each successful task completion with the task result
|
|
14
|
+
|
|
15
|
+
## [0.2.11] - 2026-03-31
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- Add GitHub issue templates, dependabot config, and PR template
|
|
19
|
+
|
|
20
|
+
## [0.2.10] - 2026-03-31
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- Standardize README badges, support section, and license format
|
|
24
|
+
|
|
25
|
+
## [0.2.9] - 2026-03-26
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
- Add Sponsor badge to README
|
|
29
|
+
- Fix License section format
|
|
30
|
+
- Sync gemspec summary with README
|
|
31
|
+
|
|
32
|
+
|
|
10
33
|
## [0.2.8] - 2026-03-24
|
|
11
34
|
|
|
12
35
|
### Fixed
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/philiprehberger/rb-task-queue/actions/workflows/ci.yml)
|
|
4
4
|
[](https://rubygems.org/gems/philiprehberger-task_queue)
|
|
5
|
-
[](https://github.com/philiprehberger/rb-task-queue/commits/main)
|
|
6
6
|
|
|
7
7
|
In-process async job queue with concurrency control
|
|
8
8
|
|
|
@@ -67,6 +67,25 @@ puts queue.stats
|
|
|
67
67
|
# => { completed: 0, failed: 2, pending: 0 }
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
### Completion callback
|
|
71
|
+
|
|
72
|
+
Register a callback to run after each successful task completion. The callback receives the return value of the task.
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
queue = Philiprehberger::TaskQueue.new(concurrency: 2)
|
|
76
|
+
|
|
77
|
+
queue.on_complete do |result|
|
|
78
|
+
puts "Task finished with: #{result}"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
queue.push { 42 }
|
|
82
|
+
queue.push { { status: "ok" } }
|
|
83
|
+
|
|
84
|
+
queue.drain(timeout: 5)
|
|
85
|
+
# Task finished with: 42
|
|
86
|
+
# Task finished with: {:status=>"ok"}
|
|
87
|
+
```
|
|
88
|
+
|
|
70
89
|
### Statistics
|
|
71
90
|
|
|
72
91
|
`stats` returns a snapshot of completed, failed, and pending counts. All counters are thread-safe and updated atomically after each task finishes.
|
|
@@ -140,11 +159,11 @@ queue.shutdown(timeout: 5)
|
|
|
140
159
|
| `#size` | _(none)_ | `Integer` | Number of pending (not yet started) tasks |
|
|
141
160
|
| `#running?` | _(none)_ | `Boolean` | Whether the queue is accepting new tasks |
|
|
142
161
|
| `#shutdown(timeout:)` | `timeout` — seconds to wait for workers (Numeric, default `30`) | `nil` | Signal workers to stop, drain remaining tasks, join threads up to `timeout` seconds |
|
|
162
|
+
| `#on_complete(&block)` | `&block` — callback receiving `(result)` | `self` | Register a callback invoked after each successful task completion with the task's return value |
|
|
143
163
|
| `#on_error(&block)` | `&block` — callback receiving `(exception, task)` | `self` | Register an error callback invoked when a task raises a `StandardError` |
|
|
144
164
|
| `#stats` | _(none)_ | `Hash` | Returns `{ completed:, failed:, pending: }` with Integer counts |
|
|
145
165
|
| `#drain(timeout:)` | `timeout` — seconds to wait (Numeric, default `30`) | `nil` | Block until all pending and in-flight tasks complete without shutting down |
|
|
146
166
|
|
|
147
|
-
|
|
148
167
|
## Development
|
|
149
168
|
|
|
150
169
|
```bash
|
|
@@ -153,6 +172,24 @@ bundle exec rspec
|
|
|
153
172
|
bundle exec rubocop
|
|
154
173
|
```
|
|
155
174
|
|
|
175
|
+
## Support
|
|
176
|
+
|
|
177
|
+
If you find this project useful:
|
|
178
|
+
|
|
179
|
+
⭐ [Star the repo](https://github.com/philiprehberger/rb-task-queue)
|
|
180
|
+
|
|
181
|
+
🐛 [Report issues](https://github.com/philiprehberger/rb-task-queue/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
|
|
182
|
+
|
|
183
|
+
💡 [Suggest features](https://github.com/philiprehberger/rb-task-queue/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)
|
|
184
|
+
|
|
185
|
+
❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)
|
|
186
|
+
|
|
187
|
+
🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)
|
|
188
|
+
|
|
189
|
+
💻 [GitHub Profile](https://github.com/philiprehberger)
|
|
190
|
+
|
|
191
|
+
🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)
|
|
192
|
+
|
|
156
193
|
## License
|
|
157
194
|
|
|
158
|
-
MIT
|
|
195
|
+
[MIT](LICENSE)
|
|
@@ -20,6 +20,7 @@ module Philiprehberger
|
|
|
20
20
|
@running = true
|
|
21
21
|
@started = false
|
|
22
22
|
@error_handler = nil
|
|
23
|
+
@complete_handler = nil
|
|
23
24
|
@stats = { completed: 0, failed: 0, in_flight: 0 }
|
|
24
25
|
end
|
|
25
26
|
|
|
@@ -34,6 +35,17 @@ module Philiprehberger
|
|
|
34
35
|
self
|
|
35
36
|
end
|
|
36
37
|
|
|
38
|
+
# Register a callback invoked after each successful task completion.
|
|
39
|
+
#
|
|
40
|
+
# The callback receives the return value of the completed task.
|
|
41
|
+
#
|
|
42
|
+
# @yield [result] called on task success
|
|
43
|
+
# @return [self]
|
|
44
|
+
def on_complete(&block)
|
|
45
|
+
@mutex.synchronize { @complete_handler = block }
|
|
46
|
+
self
|
|
47
|
+
end
|
|
48
|
+
|
|
37
49
|
# Return statistics about processed tasks.
|
|
38
50
|
#
|
|
39
51
|
# @return [Hash{Symbol => Integer}] counts for :completed, :failed, :pending
|
|
@@ -133,7 +145,8 @@ module Philiprehberger
|
|
|
133
145
|
@concurrency.times do
|
|
134
146
|
@workers << Worker.new(
|
|
135
147
|
@tasks, @mutex, @condition,
|
|
136
|
-
context: { stats: @stats, error_handler: @error_handler,
|
|
148
|
+
context: { stats: @stats, error_handler: @error_handler,
|
|
149
|
+
complete_handler: @complete_handler, drain_condition: @drain_condition }
|
|
137
150
|
)
|
|
138
151
|
end
|
|
139
152
|
@started = true
|
|
@@ -12,6 +12,7 @@ module Philiprehberger
|
|
|
12
12
|
@condition = condition
|
|
13
13
|
@stats = context[:stats]
|
|
14
14
|
@error_handler = context[:error_handler]
|
|
15
|
+
@complete_handler = context[:complete_handler]
|
|
15
16
|
@drain_condition = context[:drain_condition]
|
|
16
17
|
@running = true
|
|
17
18
|
@thread = Thread.new { run }
|
|
@@ -48,17 +49,18 @@ module Philiprehberger
|
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
def execute(task)
|
|
51
|
-
task.call
|
|
52
|
-
record_completion
|
|
52
|
+
result = task.call
|
|
53
|
+
record_completion(result)
|
|
53
54
|
rescue StandardError => e
|
|
54
55
|
record_failure(e, task)
|
|
55
56
|
end
|
|
56
57
|
|
|
57
|
-
def record_completion
|
|
58
|
+
def record_completion(result)
|
|
58
59
|
@mutex.synchronize do
|
|
59
60
|
@stats[:completed] += 1
|
|
60
61
|
@stats[:in_flight] -= 1
|
|
61
62
|
end
|
|
63
|
+
@complete_handler&.call(result)
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
def record_failure(error, task)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-task_queue
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.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-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A lightweight, zero-dependency, thread-safe in-process async job queue
|
|
14
14
|
with configurable concurrency for Ruby applications.
|
|
@@ -25,11 +25,11 @@ files:
|
|
|
25
25
|
- lib/philiprehberger/task_queue/queue.rb
|
|
26
26
|
- lib/philiprehberger/task_queue/version.rb
|
|
27
27
|
- lib/philiprehberger/task_queue/worker.rb
|
|
28
|
-
homepage: https://
|
|
28
|
+
homepage: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-task_queue
|
|
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_queue
|
|
33
33
|
source_code_uri: https://github.com/philiprehberger/rb-task-queue
|
|
34
34
|
changelog_uri: https://github.com/philiprehberger/rb-task-queue/blob/main/CHANGELOG.md
|
|
35
35
|
bug_tracker_uri: https://github.com/philiprehberger/rb-task-queue/issues
|
|
@@ -52,5 +52,5 @@ requirements: []
|
|
|
52
52
|
rubygems_version: 3.5.22
|
|
53
53
|
signing_key:
|
|
54
54
|
specification_version: 4
|
|
55
|
-
summary: In-process async job queue with concurrency control
|
|
55
|
+
summary: In-process async job queue with concurrency control for Ruby
|
|
56
56
|
test_files: []
|