philiprehberger-task_queue 0.5.0 → 0.7.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 +12 -8
- data/lib/philiprehberger/task_queue/queue.rb +13 -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: e39241a1442d74c80e1e1588468bd8ad95353479568b0be9ccf31084bd755585
|
|
4
|
+
data.tar.gz: b00310624003336ce97b36fe9931f4a11e5f4081814c3c30d2364c4f4619c527
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2c6ebf43fccdbbd00158f78859cdd79e4767e4148a82a55d81179a4be71b9346274c8ab419af1daf0a58ebd2214080bbc9b5d7b77a19267d2beefbe54b57fbf5
|
|
7
|
+
data.tar.gz: a08587cc8f79fdfcb11e3076d411225098596ad64a0b17e0c3f86e55ec142582a5018dc6832b622c77ff0bcc2bc97b55116ee3cd2384fe17bbce1fe6d4d6011c
|
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.7.0] - 2026-05-13
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Queue#busy?` — predicate returning `true` when there are pending tasks or in-flight tasks; convenient inverse of "idle" for callers polling without going through `#stats`.
|
|
14
|
+
|
|
15
|
+
## [0.6.0] - 2026-05-07
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- `Queue#concurrency` — read-only accessor for the maximum number of concurrent worker threads.
|
|
19
|
+
|
|
10
20
|
## [0.5.0] - 2026-04-19
|
|
11
21
|
|
|
12
22
|
### Added
|
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
|
|
@@ -203,6 +205,7 @@ queue.shutdown(timeout: 5)
|
|
|
203
205
|
| `#<<(callable)` | `callable` — any object responding to `#call` | `self` | Alias for `#push`; convenient for lambdas and procs |
|
|
204
206
|
| `#size` | _(none)_ | `Integer` | Number of pending (not yet started) tasks |
|
|
205
207
|
| `#empty?` | _(none)_ | `Boolean` | Whether there are no pending tasks waiting to be started |
|
|
208
|
+
| `#busy?` | _(none)_ | `Boolean` | Whether the queue has any pending tasks or in-flight tasks |
|
|
206
209
|
| `#running?` | _(none)_ | `Boolean` | Whether the queue is accepting new tasks |
|
|
207
210
|
| `#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 |
|
|
208
211
|
| `#on_complete(&block)` | `&block` — callback receiving `(result)` | `self` | Register a callback invoked after each successful task completion with the task's return value |
|
|
@@ -214,6 +217,7 @@ queue.shutdown(timeout: 5)
|
|
|
214
217
|
| `#paused?` | _(none)_ | `Boolean` | Whether the queue is currently paused |
|
|
215
218
|
| `#clear` | _(none)_ | `Integer` | Remove all pending tasks and return the number cleared |
|
|
216
219
|
| `#stats_reset!` | _(none)_ | `self` | Atomically zero the `completed` and `failed` counters while leaving pending, in-flight, workers, and callbacks untouched |
|
|
220
|
+
| `#concurrency` | _(none)_ | `Integer` | Returns the configured maximum number of concurrent worker threads |
|
|
217
221
|
|
|
218
222
|
## Development
|
|
219
223
|
|
|
@@ -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
|
|
@@ -170,6 +173,16 @@ module Philiprehberger
|
|
|
170
173
|
@mutex.synchronize { @tasks.empty? }
|
|
171
174
|
end
|
|
172
175
|
|
|
176
|
+
# Whether the queue has any pending tasks or any in-flight tasks.
|
|
177
|
+
#
|
|
178
|
+
# Convenient inverse of "idle" for callers polling without going
|
|
179
|
+
# through +stats+. Equivalent to: +!empty? || in_flight > 0+.
|
|
180
|
+
#
|
|
181
|
+
# @return [Boolean]
|
|
182
|
+
def busy?
|
|
183
|
+
@mutex.synchronize { !@tasks.empty? || @stats[:in_flight].positive? }
|
|
184
|
+
end
|
|
185
|
+
|
|
173
186
|
# Whether the queue is accepting new tasks.
|
|
174
187
|
#
|
|
175
188
|
# @return [Boolean]
|
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.7.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-14 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.
|