philiprehberger-task_queue 0.4.2 → 0.6.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 +10 -0
- data/README.md +22 -8
- data/lib/philiprehberger/task_queue/queue.rb +18 -0
- data/lib/philiprehberger/task_queue/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4729f65b6cd35decf68be8f1850b13609d87457fa049d8914f74ade8d89f9193
|
|
4
|
+
data.tar.gz: 5e26c336765fbf7e73c2bdd132a2791bbf60d0191b8748f90768cb934e4a449f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f68ed0d8be0ead8665425550efbd32d467def35234bff29875d328cabf2ab722da88789ac3a97c60b0cc29a1c299b3c015b9eea0d65ace89677592f12fd2c8d7
|
|
7
|
+
data.tar.gz: 79d4ead9724546b60ee902815899b79f573cdd6a09a1d51eb93a78dc5062355827b76b2542b1a2150db4461fa8ee459aefdf2f1374816c576fb228dd5ae41b45
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.0] - 2026-05-07
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Queue#concurrency` — read-only accessor for the maximum number of concurrent worker threads.
|
|
14
|
+
|
|
15
|
+
## [0.5.0] - 2026-04-19
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- `Queue#stats_reset!` — atomically zero the `completed` and `failed` counters while leaving pending, in-flight, workers, and callbacks untouched; useful for per-interval metrics
|
|
19
|
+
|
|
10
20
|
## [0.4.2] - 2026-04-08
|
|
11
21
|
|
|
12
22
|
### Changed
|
data/README.md
CHANGED
|
@@ -97,14 +97,16 @@ queue = Philiprehberger::TaskQueue.new(concurrency: 4)
|
|
|
97
97
|
queue.drain(timeout: 10)
|
|
98
98
|
|
|
99
99
|
stats = queue.stats
|
|
100
|
-
puts "Completed:
|
|
101
|
-
puts "Failed:
|
|
102
|
-
puts "Pending:
|
|
103
|
-
puts "In-flight:
|
|
104
|
-
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
#
|
|
100
|
+
puts "Completed: #{stats[:completed]}"
|
|
101
|
+
puts "Failed: #{stats[:failed]}"
|
|
102
|
+
puts "Pending: #{stats[:pending]}"
|
|
103
|
+
puts "In-flight: #{stats[:in_flight]}"
|
|
104
|
+
puts "Concurrency: #{queue.concurrency}"
|
|
105
|
+
# Completed: 19
|
|
106
|
+
# Failed: 1
|
|
107
|
+
# Pending: 0
|
|
108
|
+
# In-flight: 0
|
|
109
|
+
# Concurrency: 4
|
|
108
110
|
```
|
|
109
111
|
|
|
110
112
|
### Pause and resume
|
|
@@ -140,6 +142,16 @@ puts "Cleared #{cleared} tasks"
|
|
|
140
142
|
queue.shutdown(timeout: 5)
|
|
141
143
|
```
|
|
142
144
|
|
|
145
|
+
### Reset counters
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
queue = Philiprehberger::TaskQueue.new(concurrency: 4)
|
|
149
|
+
10.times { queue.push { do_work } }
|
|
150
|
+
queue.drain
|
|
151
|
+
queue.stats_reset!
|
|
152
|
+
queue.stats[:completed] # => 0
|
|
153
|
+
```
|
|
154
|
+
|
|
143
155
|
### FIFO ordering guarantees
|
|
144
156
|
|
|
145
157
|
Tasks are stored in an internal array and dequeued in FIFO order. When `concurrency` is `1`, tasks execute strictly in the order they were pushed. With higher concurrency, dequeue order is still FIFO but tasks may complete out of order depending on individual execution time.
|
|
@@ -203,6 +215,8 @@ queue.shutdown(timeout: 5)
|
|
|
203
215
|
| `#resume` | _(none)_ | `self` | Resume a paused queue, waking workers to continue processing |
|
|
204
216
|
| `#paused?` | _(none)_ | `Boolean` | Whether the queue is currently paused |
|
|
205
217
|
| `#clear` | _(none)_ | `Integer` | Remove all pending tasks and return the number cleared |
|
|
218
|
+
| `#stats_reset!` | _(none)_ | `self` | Atomically zero the `completed` and `failed` counters while leaving pending, in-flight, workers, and callbacks untouched |
|
|
219
|
+
| `#concurrency` | _(none)_ | `Integer` | Returns the configured maximum number of concurrent worker threads |
|
|
206
220
|
|
|
207
221
|
## Development
|
|
208
222
|
|
|
@@ -9,6 +9,9 @@ module Philiprehberger
|
|
|
9
9
|
# Tasks are enqueued as blocks or callable objects and executed by a pool of
|
|
10
10
|
# worker threads. The queue is fully thread-safe.
|
|
11
11
|
class Queue
|
|
12
|
+
# @return [Integer] the maximum number of concurrent worker threads
|
|
13
|
+
attr_reader :concurrency
|
|
14
|
+
|
|
12
15
|
# @param concurrency [Integer] maximum number of concurrent worker threads
|
|
13
16
|
def initialize(concurrency: 4)
|
|
14
17
|
@concurrency = concurrency
|
|
@@ -100,6 +103,21 @@ module Philiprehberger
|
|
|
100
103
|
end
|
|
101
104
|
end
|
|
102
105
|
|
|
106
|
+
# Atomically zero the +completed+ and +failed+ counters.
|
|
107
|
+
#
|
|
108
|
+
# Leaves +pending+, +in_flight+, worker threads, and registered callbacks
|
|
109
|
+
# untouched. Useful for resetting metrics between reporting intervals
|
|
110
|
+
# without shutting down the pool.
|
|
111
|
+
#
|
|
112
|
+
# @return [self]
|
|
113
|
+
def stats_reset!
|
|
114
|
+
@mutex.synchronize do
|
|
115
|
+
@stats[:completed] = 0
|
|
116
|
+
@stats[:failed] = 0
|
|
117
|
+
end
|
|
118
|
+
self
|
|
119
|
+
end
|
|
120
|
+
|
|
103
121
|
# Block until all pending tasks are complete without shutting down.
|
|
104
122
|
#
|
|
105
123
|
# @param timeout [Numeric] seconds to wait before returning
|
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.6.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-05-07 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.
|