power-queues 2.0.18 → 2.0.20
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.
- package/README.md +90 -200
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
1
|
-
# power-queues
|
|
1
|
+
# power-queues
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
queue engine built directly on **Redis Streams + Lua scripts**.
|
|
5
|
-
It is designed for real‑world distributed systems that require **high
|
|
6
|
-
throughput**, **idempotent task execution**, **automatic recovery**, and
|
|
7
|
-
**predictable performance under heavy load**.
|
|
3
|
+
## A lightweight, scalable, and high-performance queue engine for **Node.js** built on **Redis Streams** + **Lua scripts**.
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
operations
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
The library is designed for real-world distributed systems that require high throughput, idempotent task execution, automatic recovery, and predictable performance under heavy load.
|
|
6
|
+
|
|
7
|
+
Unlike traditional Redis-based queues that rely on lists or complex abstractions, **power-queues** focuses on low-level control, atomic operations, and minimal overhead, making it ideal for high-load backends, microservices, schedulers, telemetry pipelines, and data-processing clusters.
|
|
8
|
+
|
|
9
|
+
Extends **[power-redis](https://www.npmjs.com/package/power-redis)**.
|
|
14
10
|
|
|
15
11
|
<p align="center">
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
<img src="https://img.shields.io/badge/redis-streams-red?logo=redis" />
|
|
13
|
+
<img src="https://img.shields.io/badge/nodejs-queue-green?logo=node.js" />
|
|
14
|
+
<img src="https://img.shields.io/badge/typescript-ready-blue?logo=typescript" />
|
|
15
|
+
<img src="https://img.shields.io/badge/license-MIT-lightgrey" />
|
|
16
|
+
<img src="https://img.shields.io/badge/status-production-success" />
|
|
21
17
|
</p>
|
|
22
18
|
|
|
23
|
-
---
|
|
24
|
-
|
|
25
19
|
## 📚 Documentation
|
|
26
20
|
|
|
27
21
|
Full documentation is available here:
|
|
28
22
|
👉 **https://power-queues.docs.ihor.bielchenko.com**
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
# 📦 Installation
|
|
24
|
+
## 📦 Installation
|
|
33
25
|
|
|
34
26
|
``` bash
|
|
35
27
|
npm install power-queues
|
|
@@ -38,20 +30,20 @@ OR
|
|
|
38
30
|
```bash
|
|
39
31
|
yarn add power-queues
|
|
40
32
|
```
|
|
41
|
-
---
|
|
42
33
|
|
|
43
|
-
|
|
34
|
+
## 🧪 Basic usage
|
|
44
35
|
|
|
45
36
|
``` ts
|
|
46
37
|
const queue = new PowerQueues({
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
stream: 'email',
|
|
39
|
+
group: 'workers',
|
|
49
40
|
});
|
|
50
41
|
|
|
51
42
|
await queue.loadScripts(true);
|
|
52
43
|
|
|
53
|
-
await queue.addTasks(
|
|
54
|
-
|
|
44
|
+
await queue.addTasks('email', [
|
|
45
|
+
{ payload: { type: 'welcome', userId: 42 } },
|
|
46
|
+
{ payload: { type: 'hello', userId: 51 } }
|
|
55
47
|
]);
|
|
56
48
|
```
|
|
57
49
|
|
|
@@ -59,15 +51,13 @@ Worker:
|
|
|
59
51
|
|
|
60
52
|
``` ts
|
|
61
53
|
class EmailWorker extends PowerQueues {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
async onExecute(id, payload) {
|
|
55
|
+
await sendEmail(payload);
|
|
56
|
+
}
|
|
65
57
|
}
|
|
66
58
|
```
|
|
67
59
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
# ⚙ power-queues vs Existing Solutions
|
|
60
|
+
## ⚖️ power-queues vs Existing Solutions
|
|
71
61
|
|
|
72
62
|
|Feature |power-queues |BullMQ |Bee-Queue |Custom Streams|
|
|
73
63
|
|----------------------|----------------|----------- |------------|--------------|
|
|
@@ -82,30 +72,25 @@ class EmailWorker extends PowerQueues {
|
|
|
82
72
|
|Throughput |🔥 Very high |High |Medium |Depends |
|
|
83
73
|
|Overhead |Low |Medium |Low |Very high |
|
|
84
74
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
# 🚀 Key Features
|
|
88
|
-
|
|
89
|
-
### **1. Ultra‑Fast Bulk XADD (Lua‑Powered)**
|
|
75
|
+
## 🚀 Key Features & Advantages
|
|
90
76
|
|
|
91
|
-
|
|
92
|
-
-
|
|
93
|
-
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
-
|
|
77
|
+
### ✔ Ultra‑Fast Bulk XADD (Lua‑Powered)
|
|
78
|
+
- Adds thousands of messages per second using optimized Lua scripts.
|
|
79
|
+
- Minimizes round‑trips to Redis.
|
|
80
|
+
- Supports batching based on:
|
|
81
|
+
- number of tasks
|
|
82
|
+
- number of Redis arguments (safe upper bound)
|
|
83
|
+
- Outperforms typical list‑based queues and generic abstractions.
|
|
97
84
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
Every task can carry an `idemKey`, guaranteeing **exactly‑once
|
|
103
|
-
execution** even under: - worker crashes
|
|
85
|
+
### ✔ Built‑in Idempotent Workers
|
|
86
|
+
Every task can carry an `idemKey`, guaranteeing **exactly‑once execution** even under:
|
|
87
|
+
- worker crashes
|
|
104
88
|
- network interruptions
|
|
105
89
|
- duplicate task submissions
|
|
106
90
|
- process restarts
|
|
107
91
|
|
|
108
|
-
Idempotency includes:
|
|
92
|
+
Idempotency includes:
|
|
93
|
+
- Lock key
|
|
109
94
|
- Start key
|
|
110
95
|
- Done key
|
|
111
96
|
- TTL‑managed execution lock
|
|
@@ -113,196 +98,101 @@ Idempotency includes: - Lock key
|
|
|
113
98
|
- Heartbeat mechanism
|
|
114
99
|
- Waiting on TTL for contended executions
|
|
115
100
|
|
|
116
|
-
This makes the engine ideal for:
|
|
101
|
+
This makes the engine ideal for:
|
|
102
|
+
- payment processing
|
|
117
103
|
- external API calls
|
|
118
104
|
- high‑value jobs
|
|
119
105
|
- distributed pipelines
|
|
120
106
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
If a worker crashes mid‑execution, power-queues automatically detects: -
|
|
126
|
-
abandoned tasks
|
|
107
|
+
### ✔ Stuck Task Recovery (Advanced Stream Scanning)
|
|
108
|
+
If a worker crashes mid‑execution, **power-queues** automatically detects:
|
|
109
|
+
- abandoned tasks
|
|
127
110
|
- stalled locks
|
|
128
111
|
- unfinished start keys
|
|
129
112
|
|
|
130
113
|
The engine then recovers these tasks back to active processing safely
|
|
131
114
|
and efficiently.
|
|
132
115
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
-
|
|
138
|
-
-
|
|
139
|
-
- Configurable worker loop interval
|
|
140
|
-
- Individual and batch‑level error hooks
|
|
141
|
-
- Safe retry flow with per‑task attempt counters
|
|
142
|
-
|
|
143
|
-
---
|
|
116
|
+
### ✔ High‑Throughput Workers
|
|
117
|
+
- Batch execution support
|
|
118
|
+
- Parallel or sequential processing mode
|
|
119
|
+
- Configurable worker loop interval
|
|
120
|
+
- Individual and batch‑level error hooks
|
|
121
|
+
- Safe retry flow with per‑task attempt counters
|
|
144
122
|
|
|
145
|
-
###
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
`${stream}:dlq`
|
|
123
|
+
### ✔ Native DLQ (Dead‑Letter Queue)
|
|
124
|
+
When retries reach the configured limit:
|
|
125
|
+
- the task is moved into `${stream}:dlq`
|
|
149
126
|
- includes: payload, attempt count, job, timestamp, error text
|
|
150
127
|
- fully JSON‑safe
|
|
151
128
|
|
|
152
129
|
Perfect for monitoring or later re‑processing.
|
|
153
130
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
power-queues uses: - safe JSON encoding
|
|
131
|
+
### ✔ Zero‑Overhead Serialization
|
|
132
|
+
**power-queues** uses:
|
|
133
|
+
- safe JSON encoding
|
|
159
134
|
- optional "flat" key/value task format
|
|
160
135
|
- predictable and optimized payload transformation
|
|
161
136
|
|
|
162
137
|
This keeps Redis memory layout clean and eliminates overhead.
|
|
163
138
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
### **7. Complete Set of Lifecycle Hooks**
|
|
167
|
-
|
|
139
|
+
### ✔ Complete Set of Lifecycle Hooks
|
|
168
140
|
You can extend any part of the execution flow:
|
|
169
|
-
|
|
170
|
-
-
|
|
171
|
-
-
|
|
172
|
-
-
|
|
173
|
-
-
|
|
174
|
-
-
|
|
175
|
-
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
141
|
+
- `onSelected`
|
|
142
|
+
- `onExecute`
|
|
143
|
+
- `onSuccess`
|
|
144
|
+
- `onError`
|
|
145
|
+
- `onRetry`
|
|
146
|
+
- `onBatchError`
|
|
147
|
+
- `onReady`
|
|
148
|
+
|
|
149
|
+
This allows full integration with:
|
|
150
|
+
- monitoring systems
|
|
179
151
|
- logging pipelines
|
|
180
152
|
- external APM tools
|
|
181
153
|
- domain logic
|
|
182
154
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
Scripts are: - loaded once
|
|
155
|
+
### ✔ Atomic Script Loading + NOSCRIPT Recovery
|
|
156
|
+
Scripts are:
|
|
157
|
+
- loaded once
|
|
188
158
|
- cached
|
|
189
159
|
- auto‑reloaded if Redis restarts
|
|
190
160
|
- executed safely via SHA‑based calls
|
|
191
161
|
|
|
192
162
|
Ensures resilience in failover scenarios.
|
|
193
163
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
164
|
+
### ✔ Job Progress Tracking
|
|
165
|
+
Optional per‑job counters:
|
|
166
|
+
- `job:ok`
|
|
167
|
+
- `job:err`
|
|
168
|
+
- `job:ready`
|
|
199
169
|
|
|
200
170
|
Useful for UI dashboards and real‑time job progress visualization.
|
|
201
171
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
# 🛠 When to Choose power-queues
|
|
205
|
-
|
|
206
|
-
Use this engine if you need:
|
|
207
|
-
|
|
208
|
-
### **✔ High performance under load**
|
|
172
|
+
## 🧩 Extensibility
|
|
209
173
|
|
|
210
|
-
|
|
174
|
+
**power-queues** is ideal for building:
|
|
175
|
+
- task schedulers
|
|
176
|
+
- distributed cron engines
|
|
177
|
+
- ETL pipelines
|
|
178
|
+
- telemetry processors
|
|
179
|
+
- notification workers
|
|
180
|
+
- device monitoring systems
|
|
181
|
+
- AI job pipelines
|
|
182
|
+
- high-frequency background jobs
|
|
211
183
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
Exactly‑once processing for critical operations.
|
|
215
|
-
|
|
216
|
-
### **✔ Low‑level control without heavy abstractions**
|
|
217
|
-
|
|
218
|
-
No magic, no hidden states - everything is explicit.
|
|
219
|
-
|
|
220
|
-
### **✔ Predictable behavior in distributed environments**
|
|
221
|
-
|
|
222
|
-
Even with frequent worker restarts.
|
|
223
|
-
|
|
224
|
-
### **✔ Production‑grade reliability**
|
|
225
|
-
|
|
226
|
-
Backpressure, recovery, retries, dead-lettering - all included.
|
|
227
|
-
|
|
228
|
-
---
|
|
229
|
-
|
|
230
|
-
# 🏗️ Project Structure & Architecture
|
|
231
|
-
|
|
232
|
-
- Redis Streams for messaging
|
|
233
|
-
- Lua scripts for atomic operations
|
|
234
|
-
- JavaScript/TypeScript API
|
|
235
|
-
- Full worker lifecycle management
|
|
236
|
-
- Configurable backpressure & contention handling
|
|
237
|
-
- Optional job‑level progress tracking
|
|
238
|
-
|
|
239
|
-
---
|
|
240
|
-
|
|
241
|
-
# 🧩 Extensibility
|
|
242
|
-
|
|
243
|
-
power-queues is ideal for building:
|
|
244
|
-
|
|
245
|
-
- task schedulers
|
|
246
|
-
- distributed cron engines
|
|
247
|
-
- ETL pipelines
|
|
248
|
-
- telemetry processors
|
|
249
|
-
- notification workers
|
|
250
|
-
- device monitoring systems
|
|
251
|
-
- AI job pipelines
|
|
252
|
-
- high-frequency background jobs
|
|
253
|
-
|
|
254
|
-
---
|
|
255
|
-
|
|
256
|
-
# 🧱 Reliability First
|
|
184
|
+
## 🧱 Reliability First
|
|
257
185
|
|
|
258
186
|
Every part of the engine is designed to prevent:
|
|
259
|
-
|
|
260
|
-
-
|
|
261
|
-
-
|
|
262
|
-
-
|
|
263
|
-
-
|
|
264
|
-
-
|
|
265
|
-
- script desynchronization
|
|
187
|
+
- double execution
|
|
188
|
+
- stuck tasks
|
|
189
|
+
- orphan locks
|
|
190
|
+
- lost messages
|
|
191
|
+
- zombie workers
|
|
192
|
+
- script desynchronization
|
|
266
193
|
|
|
267
194
|
The heartbeat + TTL strategy guarantees that no task is "lost" even in
|
|
268
195
|
chaotic cluster environments.
|
|
269
196
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
## ⭐ Why This Project Exists
|
|
273
|
-
|
|
274
|
-
Most Node.js queue libraries are: - too slow
|
|
275
|
-
- too abstract
|
|
276
|
-
- not idempotent
|
|
277
|
-
- not safe for financial or mission‑critical workloads
|
|
278
|
-
|
|
279
|
-
power-queues was built to solve real production problems where: -
|
|
280
|
-
*duplicate tasks cost money*,
|
|
281
|
-
- *workers are unstable*,
|
|
282
|
-
- *tasks must survive restarts*,
|
|
283
|
-
- *performance matters at scale*.
|
|
284
|
-
|
|
285
|
-
If these things matter to you - this engine will feel like home.
|
|
286
|
-
|
|
287
|
-
---
|
|
288
|
-
|
|
289
|
-
## 🏷️ SEO‑Optimized Keywords (Non‑Spam)
|
|
290
|
-
|
|
291
|
-
power-queues is relevant for:
|
|
292
|
-
|
|
293
|
-
- Redis Streams queue engine
|
|
294
|
-
- Node.js stream-based queue
|
|
295
|
-
- idempotent task processing
|
|
296
|
-
- high‑performance job queue for Node.js
|
|
297
|
-
- Redis Lua queue
|
|
298
|
-
- distributed worker engine
|
|
299
|
-
- scalable background jobs
|
|
300
|
-
- enterprise-grade Redis queue
|
|
301
|
-
- microservices task runner
|
|
302
|
-
- fault-tolerant queue for Node.js
|
|
303
|
-
|
|
304
|
-
---
|
|
305
|
-
|
|
306
|
-
## 📝 License
|
|
307
|
-
|
|
197
|
+
## 📜 License
|
|
308
198
|
MIT - free for commercial and private use.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "power-queues",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.20",
|
|
4
4
|
"description": "High-performance Redis Streams queue for Node.js with Lua-powered bulk XADD, idempotent workers, heartbeat locks, stuck-task recovery, retries, DLQ, and distributed processing.",
|
|
5
5
|
"author": "ihor-bielchenko",
|
|
6
6
|
"license": "MIT",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
],
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"full-utils": "^2.0.5",
|
|
85
|
-
"power-redis": "^2.0.
|
|
85
|
+
"power-redis": "^2.0.10",
|
|
86
86
|
"uuid": "^13.0.0"
|
|
87
87
|
}
|
|
88
88
|
}
|