@nathapp/nestjs-queue 2.1.0-rc.1
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/CLAUDE.md +106 -0
- package/TODO.md +44 -0
- package/dist/constant/index.d.ts +1 -0
- package/dist/constant/index.js +18 -0
- package/dist/constant/index.js.map +1 -0
- package/dist/constant/queue.constant.d.ts +6 -0
- package/dist/constant/queue.constant.js +10 -0
- package/dist/constant/queue.constant.js.map +1 -0
- package/dist/decorator/index.d.ts +3 -0
- package/dist/decorator/index.js +20 -0
- package/dist/decorator/index.js.map +1 -0
- package/dist/decorator/on-queue-event.decorator.d.ts +6 -0
- package/dist/decorator/on-queue-event.decorator.js +18 -0
- package/dist/decorator/on-queue-event.decorator.js.map +1 -0
- package/dist/decorator/process.decorator.d.ts +5 -0
- package/dist/decorator/process.decorator.js +18 -0
- package/dist/decorator/process.decorator.js.map +1 -0
- package/dist/decorator/processor.decorator.d.ts +5 -0
- package/dist/decorator/processor.decorator.js +12 -0
- package/dist/decorator/processor.decorator.js.map +1 -0
- package/dist/enum/index.d.ts +3 -0
- package/dist/enum/index.js +20 -0
- package/dist/enum/index.js.map +1 -0
- package/dist/enum/job-status.enum.d.ts +8 -0
- package/dist/enum/job-status.enum.js +13 -0
- package/dist/enum/job-status.enum.js.map +1 -0
- package/dist/enum/provider.enum.d.ts +7 -0
- package/dist/enum/provider.enum.js +12 -0
- package/dist/enum/provider.enum.js.map +1 -0
- package/dist/enum/queue-event.enum.d.ts +11 -0
- package/dist/enum/queue-event.enum.js +16 -0
- package/dist/enum/queue-event.enum.js.map +1 -0
- package/dist/explorer/index.d.ts +1 -0
- package/dist/explorer/index.js +18 -0
- package/dist/explorer/index.js.map +1 -0
- package/dist/explorer/processor.explorer.d.ts +25 -0
- package/dist/explorer/processor.explorer.js +241 -0
- package/dist/explorer/processor.explorer.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/interface/circuit-breaker.interface.d.ts +21 -0
- package/dist/interface/circuit-breaker.interface.js +10 -0
- package/dist/interface/circuit-breaker.interface.js.map +1 -0
- package/dist/interface/health.interface.d.ts +12 -0
- package/dist/interface/health.interface.js +3 -0
- package/dist/interface/health.interface.js.map +1 -0
- package/dist/interface/idempotency-store.interface.d.ts +14 -0
- package/dist/interface/idempotency-store.interface.js +3 -0
- package/dist/interface/idempotency-store.interface.js.map +1 -0
- package/dist/interface/index.d.ts +5 -0
- package/dist/interface/index.js +22 -0
- package/dist/interface/index.js.map +1 -0
- package/dist/interface/job.interface.d.ts +56 -0
- package/dist/interface/job.interface.js +3 -0
- package/dist/interface/job.interface.js.map +1 -0
- package/dist/interface/metrics.interface.d.ts +12 -0
- package/dist/interface/metrics.interface.js +3 -0
- package/dist/interface/metrics.interface.js.map +1 -0
- package/dist/interface/queue-options.interface.d.ts +84 -0
- package/dist/interface/queue-options.interface.js +3 -0
- package/dist/interface/queue-options.interface.js.map +1 -0
- package/dist/interface/queue-provider.interface.d.ts +55 -0
- package/dist/interface/queue-provider.interface.js +7 -0
- package/dist/interface/queue-provider.interface.js.map +1 -0
- package/dist/module/index.d.ts +3 -0
- package/dist/module/index.js +20 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/queue.module-definition.d.ts +2 -0
- package/dist/module/queue.module-definition.js +11 -0
- package/dist/module/queue.module-definition.js.map +1 -0
- package/dist/module/queue.module.d.ts +3 -0
- package/dist/module/queue.module.js +26 -0
- package/dist/module/queue.module.js.map +1 -0
- package/dist/module/queue.provider.d.ts +2 -0
- package/dist/module/queue.provider.js +57 -0
- package/dist/module/queue.provider.js.map +1 -0
- package/dist/provider/bullmq/bullmq.options.d.ts +12 -0
- package/dist/provider/bullmq/bullmq.options.js +3 -0
- package/dist/provider/bullmq/bullmq.options.js.map +1 -0
- package/dist/provider/bullmq/bullmq.provider.d.ts +52 -0
- package/dist/provider/bullmq/bullmq.provider.js +476 -0
- package/dist/provider/bullmq/bullmq.provider.js.map +1 -0
- package/dist/provider/bullmq/index.d.ts +1 -0
- package/dist/provider/bullmq/index.js +18 -0
- package/dist/provider/bullmq/index.js.map +1 -0
- package/dist/provider/index.d.ts +4 -0
- package/dist/provider/index.js +21 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/provider/kafka/index.d.ts +1 -0
- package/dist/provider/kafka/index.js +18 -0
- package/dist/provider/kafka/index.js.map +1 -0
- package/dist/provider/kafka/kafka.provider.d.ts +59 -0
- package/dist/provider/kafka/kafka.provider.js +598 -0
- package/dist/provider/kafka/kafka.provider.js.map +1 -0
- package/dist/provider/rabbitmq/index.d.ts +1 -0
- package/dist/provider/rabbitmq/index.js +18 -0
- package/dist/provider/rabbitmq/index.js.map +1 -0
- package/dist/provider/rabbitmq/rabbitmq.provider.d.ts +48 -0
- package/dist/provider/rabbitmq/rabbitmq.provider.js +498 -0
- package/dist/provider/rabbitmq/rabbitmq.provider.js.map +1 -0
- package/dist/provider/redis-pubsub/index.d.ts +1 -0
- package/dist/provider/redis-pubsub/index.js +18 -0
- package/dist/provider/redis-pubsub/index.js.map +1 -0
- package/dist/provider/redis-pubsub/redis-pubsub.provider.d.ts +40 -0
- package/dist/provider/redis-pubsub/redis-pubsub.provider.js +226 -0
- package/dist/provider/redis-pubsub/redis-pubsub.provider.js.map +1 -0
- package/dist/service/index.d.ts +1 -0
- package/dist/service/index.js +18 -0
- package/dist/service/index.js.map +1 -0
- package/dist/service/queue.service.d.ts +36 -0
- package/dist/service/queue.service.js +89 -0
- package/dist/service/queue.service.js.map +1 -0
- package/dist/store/in-memory-idempotency.store.d.ts +15 -0
- package/dist/store/in-memory-idempotency.store.js +84 -0
- package/dist/store/in-memory-idempotency.store.js.map +1 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.js +6 -0
- package/dist/store/index.js.map +1 -0
- package/dist/utils/circuit-breaker.d.ts +30 -0
- package/dist/utils/circuit-breaker.js +133 -0
- package/dist/utils/circuit-breaker.js.map +1 -0
- package/dist/utils/delayed-scheduler.d.ts +16 -0
- package/dist/utils/delayed-scheduler.js +100 -0
- package/dist/utils/delayed-scheduler.js.map +1 -0
- package/dist/utils/errors.d.ts +23 -0
- package/dist/utils/errors.js +85 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/lock-renewal.d.ts +14 -0
- package/dist/utils/lock-renewal.js +61 -0
- package/dist/utils/lock-renewal.js.map +1 -0
- package/dist/utils/redis-idempotency-store.d.ts +21 -0
- package/dist/utils/redis-idempotency-store.js +88 -0
- package/dist/utils/redis-idempotency-store.js.map +1 -0
- package/dist/utils/sanitize.d.ts +3 -0
- package/dist/utils/sanitize.js +55 -0
- package/dist/utils/sanitize.js.map +1 -0
- package/dist/utils/validation.d.ts +8 -0
- package/dist/utils/validation.js +60 -0
- package/dist/utils/validation.js.map +1 -0
- package/docker-compose.e2e.yml +69 -0
- package/docs/FINAL_CODE_REVIEW.md +328 -0
- package/docs/IMPLEMENTATION_PLAN.md +748 -0
- package/docs/archive/CIRCUIT_BREAKER_PLAN.md +35 -0
- package/docs/archive/CODE_REVIEW.md +596 -0
- package/docs/archive/CODE_REVIEW_V2.md +1081 -0
- package/docs/archive/CODE_REVIEW_V3.md +402 -0
- package/docs/archive/IMPLEMENTATION_PLAN.md +505 -0
- package/docs/archive/IMPLEMENTATION_PLAN_BUGFIX.md +428 -0
- package/package.json +70 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
# Code Review V3: Enhancement Recommendations
|
|
2
|
+
|
|
3
|
+
**Date**: 2026-02-08
|
|
4
|
+
**Reviewer**: Sabrina
|
|
5
|
+
**Package**: @nathapp/nestjs-queue
|
|
6
|
+
**Lines Reviewed**: ~3,700
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Executive Summary
|
|
11
|
+
|
|
12
|
+
The package is **production-ready** with solid fundamentals:
|
|
13
|
+
- ✅ Clean provider abstraction pattern
|
|
14
|
+
- ✅ Graceful shutdown with timeouts
|
|
15
|
+
- ✅ Idempotency store for RabbitMQ
|
|
16
|
+
- ✅ Single-worker routing in ProcessorExplorer
|
|
17
|
+
- ✅ CorrelationId propagation
|
|
18
|
+
|
|
19
|
+
However, there are **10 enhancement opportunities** ranging from quick wins to strategic improvements.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 🔴 P0 - Critical Issues (None Found)
|
|
24
|
+
|
|
25
|
+
No critical bugs identified. Previous P0 issues have been resolved.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 🟡 P1 - High Priority Enhancements
|
|
30
|
+
|
|
31
|
+
### 1. Missing `off()` Method for Event Listeners
|
|
32
|
+
|
|
33
|
+
**Location**: All providers
|
|
34
|
+
**Impact**: Memory leak in long-running apps with dynamic listeners
|
|
35
|
+
|
|
36
|
+
**Current State**: `on()` adds listeners but there's no way to remove them.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
// Current - no way to unsubscribe
|
|
40
|
+
queueService.on('orders', QueueEvent.COMPLETED, myHandler);
|
|
41
|
+
// myHandler stays forever, even if component is destroyed
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Recommendation**:
|
|
45
|
+
```typescript
|
|
46
|
+
// Add to IQueueProvider interface
|
|
47
|
+
off(
|
|
48
|
+
queueName: string,
|
|
49
|
+
event: QueueEvent,
|
|
50
|
+
callback: (job: IJob, result?: any) => void,
|
|
51
|
+
): void;
|
|
52
|
+
|
|
53
|
+
// Implementation pattern
|
|
54
|
+
private readonly listenerRegistry = new Map<Function, Function>(); // original -> wrapped
|
|
55
|
+
|
|
56
|
+
on(queueName, event, callback, filter?) {
|
|
57
|
+
const wrappedCallback = (job, result) => { /* filtering logic */ callback(job, result); };
|
|
58
|
+
this.listenerRegistry.set(callback, wrappedCallback);
|
|
59
|
+
// ... register wrappedCallback
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
off(queueName, event, callback) {
|
|
63
|
+
const wrapped = this.listenerRegistry.get(callback);
|
|
64
|
+
if (wrapped) {
|
|
65
|
+
// Remove from queueListeners
|
|
66
|
+
this.listenerRegistry.delete(callback);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### 2. BullMQ: Duplicate Worker Registration Still Possible
|
|
74
|
+
|
|
75
|
+
**Location**: `bullmq.provider.ts` line 217-221
|
|
76
|
+
|
|
77
|
+
**Issue**: The `process()` method skips if a worker exists, but doesn't throw. This silently ignores the second registration.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
if (this.workers.has(workerKey)) {
|
|
81
|
+
this.logger.warn(`Worker already exists for ${workerKey}`);
|
|
82
|
+
return; // Silently ignored!
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Recommendation**: Throw an error or return a boolean to let callers know registration failed.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
async process<T>(...): Promise<boolean> {
|
|
90
|
+
if (this.workers.has(workerKey)) {
|
|
91
|
+
this.logger.warn(`Worker already exists for ${workerKey}`);
|
|
92
|
+
return false; // Or throw new QueueOperationError('WORKER_EXISTS', ...)
|
|
93
|
+
}
|
|
94
|
+
// ... register
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
### 3. Kafka: Missing Idempotency Store Integration
|
|
102
|
+
|
|
103
|
+
**Location**: `kafka.provider.ts`
|
|
104
|
+
|
|
105
|
+
**Gap**: RabbitMQ has `idempotency` option in config, but Kafka doesn't. For exactly-once semantics in consumer groups with rebalancing, idempotency is critical.
|
|
106
|
+
|
|
107
|
+
**Recommendation**: Add `KafkaQueueOptions.idempotency` similar to RabbitMQ:
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
// In kafka.provider.ts process()
|
|
111
|
+
if (idempotencyStore) {
|
|
112
|
+
const canProcess = await idempotencyStore.markProcessing(job.id, lockTtl);
|
|
113
|
+
if (!canProcess) {
|
|
114
|
+
return; // Skip - already processed during rebalance
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
### 4. Missing Health Check Interface
|
|
122
|
+
|
|
123
|
+
**Location**: All providers
|
|
124
|
+
|
|
125
|
+
**Gap**: No way to check if connections are healthy for k8s probes.
|
|
126
|
+
|
|
127
|
+
**Recommendation**:
|
|
128
|
+
```typescript
|
|
129
|
+
// Add to IQueueProvider
|
|
130
|
+
interface HealthCheckResult {
|
|
131
|
+
healthy: boolean;
|
|
132
|
+
provider: string;
|
|
133
|
+
connections: { name: string; status: 'connected' | 'disconnected' | 'error' }[];
|
|
134
|
+
latencyMs?: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
isHealthy(): Promise<HealthCheckResult>;
|
|
138
|
+
|
|
139
|
+
// Example implementation for BullMQ
|
|
140
|
+
async isHealthy(): Promise<HealthCheckResult> {
|
|
141
|
+
try {
|
|
142
|
+
const queue = this.getQueue('__health__');
|
|
143
|
+
const start = Date.now();
|
|
144
|
+
await queue.client.ping();
|
|
145
|
+
return {
|
|
146
|
+
healthy: true,
|
|
147
|
+
provider: 'bullmq',
|
|
148
|
+
connections: [{ name: 'redis', status: 'connected' }],
|
|
149
|
+
latencyMs: Date.now() - start,
|
|
150
|
+
};
|
|
151
|
+
} catch (error) {
|
|
152
|
+
return { healthy: false, provider: 'bullmq', connections: [{ name: 'redis', status: 'error' }] };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
### 5. Metrics/Observability Hooks Missing
|
|
160
|
+
|
|
161
|
+
**Location**: All providers
|
|
162
|
+
|
|
163
|
+
**Gap**: No way to integrate with Prometheus/OpenTelemetry.
|
|
164
|
+
|
|
165
|
+
**Recommendation**: Add optional metrics collector:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
interface QueueMetrics {
|
|
169
|
+
jobAdded(queueName: string, jobName: string, opts?: { delay?: number }): void;
|
|
170
|
+
jobStarted(queueName: string, jobId: string): void;
|
|
171
|
+
jobCompleted(queueName: string, jobId: string, durationMs: number): void;
|
|
172
|
+
jobFailed(queueName: string, jobId: string, error: string): void;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// In QueueModuleOptions
|
|
176
|
+
metrics?: QueueMetrics;
|
|
177
|
+
|
|
178
|
+
// Usage in provider
|
|
179
|
+
this.metrics?.jobStarted(queueName, job.id);
|
|
180
|
+
const start = Date.now();
|
|
181
|
+
const result = await processor(job);
|
|
182
|
+
this.metrics?.jobCompleted(queueName, job.id, Date.now() - start);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## 🟢 P2 - Medium Priority Enhancements
|
|
188
|
+
|
|
189
|
+
### 6. RabbitMQ: `addBulk()` is Not Atomic
|
|
190
|
+
|
|
191
|
+
**Location**: `rabbitmq.provider.ts` line 195-203
|
|
192
|
+
|
|
193
|
+
**Current**: Sequential `add()` calls - if one fails, partial jobs are added.
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
async addBulk<T>(...): Promise<IJob<T>[]> {
|
|
197
|
+
const createdJobs: IJob<T>[] = [];
|
|
198
|
+
for (const j of jobs) {
|
|
199
|
+
const job = await this.add(...); // Can fail mid-batch!
|
|
200
|
+
createdJobs.push(job);
|
|
201
|
+
}
|
|
202
|
+
return createdJobs;
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**Recommendation**: Use channel confirm mode for batch publishing:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
async addBulk<T>(...): Promise<IJob<T>[]> {
|
|
210
|
+
const channel = await this.getChannel(queueName);
|
|
211
|
+
|
|
212
|
+
// Use waitForConfirms for atomicity
|
|
213
|
+
await channel.addSetup(async (ch: amqp.ConfirmChannel) => {
|
|
214
|
+
for (const j of jobs) {
|
|
215
|
+
ch.sendToQueue(queueName, buffer, options);
|
|
216
|
+
}
|
|
217
|
+
await ch.waitForConfirms();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
return createdJobs;
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### 7. Kafka: CorrelationId Not Propagated
|
|
227
|
+
|
|
228
|
+
**Location**: `kafka.provider.ts`
|
|
229
|
+
|
|
230
|
+
**Gap**: RabbitMQ and BullMQ propagate `correlationId`, but Kafka doesn't extract or forward it.
|
|
231
|
+
|
|
232
|
+
**Current in `add()`**:
|
|
233
|
+
```typescript
|
|
234
|
+
const headers: Record<string, string> = {
|
|
235
|
+
'x-job-name': jobName,
|
|
236
|
+
'x-job-id': job.id,
|
|
237
|
+
// Missing: 'x-correlation-id'
|
|
238
|
+
};
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Recommendation**:
|
|
242
|
+
```typescript
|
|
243
|
+
// In add()
|
|
244
|
+
if (opts?.correlationId) {
|
|
245
|
+
headers['x-correlation-id'] = opts.correlationId;
|
|
246
|
+
job.correlationId = opts.correlationId;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// In process()
|
|
250
|
+
job.correlationId = message.headers?.['x-correlation-id']?.toString();
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
### 8. ProcessorExplorer: No Error Boundary per Handler
|
|
256
|
+
|
|
257
|
+
**Location**: `processor.explorer.ts` line 139-150
|
|
258
|
+
|
|
259
|
+
**Issue**: If a named handler throws, the error bubbles up without context.
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
const routerHandler = async (job: IJob): Promise<any> => {
|
|
263
|
+
const namedHandler = namedHandlers.get(job.name);
|
|
264
|
+
if (namedHandler) {
|
|
265
|
+
return namedHandler(job); // No try/catch - raw error propagation
|
|
266
|
+
}
|
|
267
|
+
// ...
|
|
268
|
+
};
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**Recommendation**: Wrap each handler for better error context:
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
const routerHandler = async (job: IJob): Promise<any> => {
|
|
275
|
+
const namedHandler = namedHandlers.get(job.name);
|
|
276
|
+
if (namedHandler) {
|
|
277
|
+
try {
|
|
278
|
+
return await namedHandler(job);
|
|
279
|
+
} catch (error) {
|
|
280
|
+
// Add context for debugging
|
|
281
|
+
error.handlerName = job.name;
|
|
282
|
+
error.queueName = queueName;
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
// ...
|
|
287
|
+
};
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
### 9. Missing Job Progress API for Kafka/RabbitMQ
|
|
293
|
+
|
|
294
|
+
**Location**: `IQueueProvider` interface
|
|
295
|
+
|
|
296
|
+
**Gap**: BullMQ supports `job.updateProgress()` but the interface doesn't define it, and Kafka/RabbitMQ don't implement progress tracking.
|
|
297
|
+
|
|
298
|
+
**Recommendation**: Add optional progress method:
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
// In IJob
|
|
302
|
+
progress?: number;
|
|
303
|
+
|
|
304
|
+
// In IQueueProvider (optional implementation)
|
|
305
|
+
updateProgress?(queueName: string, jobId: string, progress: number): Promise<void>;
|
|
306
|
+
|
|
307
|
+
// For Kafka/RabbitMQ - emit as event (since job state isn't stored)
|
|
308
|
+
async updateProgress(queueName, jobId, progress) {
|
|
309
|
+
this.emitEvent(queueName, QueueEvent.PROGRESS, { id: jobId, progress });
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
### 10. ShutdownOptions Not Exposed in QueueService
|
|
316
|
+
|
|
317
|
+
**Location**: `queue.service.ts` line 145
|
|
318
|
+
|
|
319
|
+
**Issue**: `onModuleDestroy()` calls `close()` with no options. In production, you may want to control drain behavior.
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
async onModuleDestroy(): Promise<void> {
|
|
323
|
+
await this.provider.close(); // No options passed!
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**Recommendation**:
|
|
328
|
+
```typescript
|
|
329
|
+
// Add to QueueModuleOptions
|
|
330
|
+
shutdownOptions?: ShutdownOptions;
|
|
331
|
+
|
|
332
|
+
// In QueueService
|
|
333
|
+
constructor(
|
|
334
|
+
@Inject(QUEUE_PROVIDER) private readonly provider: IQueueProvider,
|
|
335
|
+
@Inject(MODULE_OPTIONS_TOKEN) private readonly options: QueueModuleOptions,
|
|
336
|
+
) {}
|
|
337
|
+
|
|
338
|
+
async onModuleDestroy(): Promise<void> {
|
|
339
|
+
await this.provider.close(this.options.shutdownOptions);
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## 🔵 P3 - Nice to Have
|
|
346
|
+
|
|
347
|
+
### 11. Add `getQueueStats()` Method
|
|
348
|
+
|
|
349
|
+
Return queue depth, consumer count, and throughput estimates.
|
|
350
|
+
|
|
351
|
+
### 12. Support for Job Scheduling (Cron-like)
|
|
352
|
+
|
|
353
|
+
BullMQ has `repeat` options; expose a unified API for scheduled jobs.
|
|
354
|
+
|
|
355
|
+
### 13. Job TTL Enforcement
|
|
356
|
+
|
|
357
|
+
Add `ttl` option to auto-expire jobs that haven't been processed.
|
|
358
|
+
|
|
359
|
+
### 14. Circuit Breaker Pattern
|
|
360
|
+
|
|
361
|
+
Add optional circuit breaker for downstream service protection.
|
|
362
|
+
|
|
363
|
+
### 15. Batch Processing Mode
|
|
364
|
+
|
|
365
|
+
Process multiple jobs in a single callback for high-throughput scenarios.
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## Implementation Priority Matrix
|
|
370
|
+
|
|
371
|
+
| Enhancement | Impact | Effort | Priority |
|
|
372
|
+
|-------------|--------|--------|----------|
|
|
373
|
+
| `off()` method | High | Low | P1 |
|
|
374
|
+
| Health checks | High | Medium | P1 |
|
|
375
|
+
| Kafka idempotency | High | Medium | P1 |
|
|
376
|
+
| Metrics hooks | High | Medium | P1 |
|
|
377
|
+
| Duplicate worker handling | Medium | Low | P1 |
|
|
378
|
+
| RabbitMQ atomic bulk | Medium | Medium | P2 |
|
|
379
|
+
| Kafka correlationId | Medium | Low | P2 |
|
|
380
|
+
| Handler error context | Medium | Low | P2 |
|
|
381
|
+
| Progress API | Low | Medium | P2 |
|
|
382
|
+
| Shutdown options | Medium | Low | P2 |
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
## Summary
|
|
387
|
+
|
|
388
|
+
The package has **excellent fundamentals** and is ready for production use. The suggested enhancements focus on:
|
|
389
|
+
|
|
390
|
+
1. **Observability** - Health checks, metrics, progress tracking
|
|
391
|
+
2. **Reliability** - Idempotency for Kafka, atomic bulk operations
|
|
392
|
+
3. **Developer Experience** - Better error context, event unsubscription
|
|
393
|
+
|
|
394
|
+
**Recommended Next Steps**:
|
|
395
|
+
1. Implement `off()` method (quick win, prevents memory leaks)
|
|
396
|
+
2. Add health check interface (critical for k8s deployments)
|
|
397
|
+
3. Add Kafka correlationId propagation (consistency with other providers)
|
|
398
|
+
4. Add metrics hooks (optional but valuable for production)
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
*Review completed by Sabrina on 2026-02-08*
|