@nathapp/nestjs-queue 2.1.0-rc.1 → 2.1.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.
- package/TODO.md +15 -0
- package/dist/decorator/batch-process.decorator.d.ts +11 -0
- package/dist/decorator/batch-process.decorator.js +13 -0
- package/dist/decorator/batch-process.decorator.js.map +1 -0
- package/dist/decorator/index.d.ts +1 -0
- package/dist/decorator/index.js +1 -0
- package/dist/decorator/index.js.map +1 -1
- package/dist/enum/provider.enum.d.ts +0 -1
- package/dist/enum/provider.enum.js +0 -1
- package/dist/enum/provider.enum.js.map +1 -1
- package/dist/explorer/processor.explorer.d.ts +3 -0
- package/dist/explorer/processor.explorer.js +43 -1
- package/dist/explorer/processor.explorer.js.map +1 -1
- package/dist/interface/batch.interface.d.ts +23 -0
- package/dist/interface/batch.interface.js +3 -0
- package/dist/interface/batch.interface.js.map +1 -0
- package/dist/interface/index.d.ts +1 -0
- package/dist/interface/index.js +1 -0
- package/dist/interface/index.js.map +1 -1
- package/dist/interface/queue-options.interface.d.ts +1 -9
- package/dist/interface/queue-provider.interface.d.ts +13 -0
- package/dist/interface/queue-provider.interface.js.map +1 -1
- package/dist/module/queue.provider.js +0 -3
- package/dist/module/queue.provider.js.map +1 -1
- package/dist/provider/bullmq/bullmq.provider.d.ts +9 -0
- package/dist/provider/bullmq/bullmq.provider.js +104 -0
- package/dist/provider/bullmq/bullmq.provider.js.map +1 -1
- package/dist/provider/index.d.ts +0 -1
- package/dist/provider/index.js +0 -1
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/kafka/kafka.provider.d.ts +7 -0
- package/dist/provider/kafka/kafka.provider.js +150 -0
- package/dist/provider/kafka/kafka.provider.js.map +1 -1
- package/dist/provider/rabbitmq/rabbitmq.provider.d.ts +9 -0
- package/dist/provider/rabbitmq/rabbitmq.provider.js +171 -0
- package/dist/provider/rabbitmq/rabbitmq.provider.js.map +1 -1
- package/dist/utils/delayed-scheduler.js +2 -1
- package/dist/utils/delayed-scheduler.js.map +1 -1
- package/docs/BATCH_PROCESSING_PLAN.md +581 -0
- package/docs/COVERAGE_IMPLEMENTATION_TASKS.md +664 -0
- package/docs/COVERAGE_RECOVERY_PLAN.md +254 -0
- package/package.json +3 -2
- package/dist/provider/redis-pubsub/index.d.ts +0 -1
- package/dist/provider/redis-pubsub/index.js +0 -18
- package/dist/provider/redis-pubsub/index.js.map +0 -1
- package/dist/provider/redis-pubsub/redis-pubsub.provider.d.ts +0 -40
- package/dist/provider/redis-pubsub/redis-pubsub.provider.js +0 -226
- package/dist/provider/redis-pubsub/redis-pubsub.provider.js.map +0 -1
package/TODO.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# TODO: @nathapp/nestjs-queue
|
|
2
2
|
|
|
3
|
+
## 🟡 In Progress
|
|
4
|
+
- [ ] Monitor prerelease pipeline for Batch Processing feature
|
|
5
|
+
|
|
6
|
+
## 🔴 Awaiting Approval
|
|
7
|
+
- [ ] ACTION REQUIRED: Approve merge of `queue-module` branch into `master` after prerelease validation
|
|
8
|
+
|
|
3
9
|
## ✅ Done
|
|
10
|
+
- [x] Batch Processing Mode (docs/BATCH_PROCESSING_PLAN.md)
|
|
11
|
+
- [x] Full implementation for BullMQ, Kafka, RabbitMQ
|
|
12
|
+
- [x] @BatchProcess Decorator & ProcessorExplorer Integration
|
|
13
|
+
- [x] Integration Verification Tests
|
|
14
|
+
- [x] Coverage Recovery (80.07% global branches)
|
|
15
|
+
- [x] P1/P2 Enhancements (Circuit Breaker, Idempotency, Lock Renewal)
|
|
16
|
+
- [x] All 438 unit tests passing (Redis Pub/Sub provider removed)
|
|
17
|
+
- [x] Removed Redis Pub/Sub provider (unsuitable for job queues)
|
|
18
|
+
- [x] E2E Validation confirmed by William
|
|
4
19
|
- [x] Phase 0: Reach 80% Branch Coverage (Final: 81.08%)
|
|
5
20
|
- [x] test/provider/rabbitmq.provider.spec.ts (80.3% coverage)
|
|
6
21
|
- [x] test/provider/kafka.provider.spec.ts (82.1% coverage)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const BATCH_PROCESS_METADATA = "BATCH_PROCESS_METADATA";
|
|
2
|
+
export interface BatchProcessDecoratorOptions {
|
|
3
|
+
name?: string;
|
|
4
|
+
batchSize?: number;
|
|
5
|
+
batchTimeout?: number;
|
|
6
|
+
parallel?: boolean;
|
|
7
|
+
maxParallel?: number;
|
|
8
|
+
continueOnError?: boolean;
|
|
9
|
+
retryFailedIndividually?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function BatchProcess(options?: BatchProcessDecoratorOptions): MethodDecorator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BATCH_PROCESS_METADATA = void 0;
|
|
4
|
+
exports.BatchProcess = BatchProcess;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
exports.BATCH_PROCESS_METADATA = 'BATCH_PROCESS_METADATA';
|
|
7
|
+
function BatchProcess(options = {}) {
|
|
8
|
+
return (0, common_1.SetMetadata)(exports.BATCH_PROCESS_METADATA, {
|
|
9
|
+
...options,
|
|
10
|
+
methodName: undefined,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=batch-process.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-process.decorator.js","sourceRoot":"","sources":["../../lib/decorator/batch-process.decorator.ts"],"names":[],"mappings":";;;AA6DA,oCAKC;AAlED,2CAA6C;AAEhC,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AA2D/D,SAAgB,YAAY,CAAC,UAAwC,EAAE;IACrE,OAAO,IAAA,oBAAW,EAAC,8BAAsB,EAAE;QACzC,GAAG,OAAO;QACV,UAAU,EAAE,SAAS;KACtB,CAAC,CAAC;AACL,CAAC"}
|
package/dist/decorator/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./processor.decorator"), exports);
|
|
18
18
|
__exportStar(require("./process.decorator"), exports);
|
|
19
19
|
__exportStar(require("./on-queue-event.decorator"), exports);
|
|
20
|
+
__exportStar(require("./batch-process.decorator"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/decorator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,sDAAoC;AACpC,6DAA2C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/decorator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,sDAAoC;AACpC,6DAA2C;AAC3C,4DAA0C"}
|
|
@@ -6,7 +6,6 @@ var QueueProviderType;
|
|
|
6
6
|
QueueProviderType["BULLMQ"] = "bullmq";
|
|
7
7
|
QueueProviderType["KAFKA"] = "kafka";
|
|
8
8
|
QueueProviderType["RABBITMQ"] = "rabbitmq";
|
|
9
|
-
QueueProviderType["REDIS_PUBSUB"] = "redis-pubsub";
|
|
10
9
|
QueueProviderType["CUSTOM"] = "custom";
|
|
11
10
|
})(QueueProviderType || (exports.QueueProviderType = QueueProviderType = {}));
|
|
12
11
|
//# sourceMappingURL=provider.enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.enum.js","sourceRoot":"","sources":["../../lib/enum/provider.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"provider.enum.js","sourceRoot":"","sources":["../../lib/enum/provider.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,oCAAe,CAAA;IACf,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;AACnB,CAAC,EALW,iBAAiB,iCAAjB,iBAAiB,QAK5B"}
|
|
@@ -10,14 +10,17 @@ export declare class ProcessorExplorer implements OnModuleInit, OnModuleDestroy
|
|
|
10
10
|
private readonly moduleOptions?;
|
|
11
11
|
private readonly logger;
|
|
12
12
|
private readonly queueHandlers;
|
|
13
|
+
private readonly batchProcessors;
|
|
13
14
|
private readonly circuitBreakers;
|
|
14
15
|
constructor(discoveryService: DiscoveryService, metadataScanner: MetadataScanner, reflector: Reflector, queueProvider: IQueueProvider, moduleOptions?: QueueModuleOptions);
|
|
15
16
|
onModuleInit(): Promise<void>;
|
|
16
17
|
onModuleDestroy(): void;
|
|
17
18
|
private explore;
|
|
18
19
|
private collectProcessHandler;
|
|
20
|
+
private collectBatchProcessHandler;
|
|
19
21
|
private mergeCircuitBreakerOptions;
|
|
20
22
|
private registerQueueWorkers;
|
|
23
|
+
private registerBatchProcessors;
|
|
21
24
|
private getMetricsHook;
|
|
22
25
|
private registerEventHandler;
|
|
23
26
|
resetCircuitBreaker(queueName: string): void;
|
|
@@ -19,6 +19,7 @@ const core_1 = require("@nestjs/core");
|
|
|
19
19
|
const queue_constant_1 = require("../constant/queue.constant");
|
|
20
20
|
const queue_module_definition_1 = require("../module/queue.module-definition");
|
|
21
21
|
const circuit_breaker_1 = require("../utils/circuit-breaker");
|
|
22
|
+
const batch_process_decorator_1 = require("../decorator/batch-process.decorator");
|
|
22
23
|
let ProcessorExplorer = ProcessorExplorer_1 = class ProcessorExplorer {
|
|
23
24
|
constructor(discoveryService, metadataScanner, reflector, queueProvider, moduleOptions) {
|
|
24
25
|
this.discoveryService = discoveryService;
|
|
@@ -28,6 +29,7 @@ let ProcessorExplorer = ProcessorExplorer_1 = class ProcessorExplorer {
|
|
|
28
29
|
this.moduleOptions = moduleOptions;
|
|
29
30
|
this.logger = new common_1.Logger(ProcessorExplorer_1.name);
|
|
30
31
|
this.queueHandlers = new Map();
|
|
32
|
+
this.batchProcessors = new Map();
|
|
31
33
|
this.circuitBreakers = new Map();
|
|
32
34
|
}
|
|
33
35
|
async onModuleInit() {
|
|
@@ -59,10 +61,12 @@ let ProcessorExplorer = ProcessorExplorer_1 = class ProcessorExplorer {
|
|
|
59
61
|
const methodNames = this.metadataScanner.getAllMethodNames(prototype);
|
|
60
62
|
for (const methodName of methodNames) {
|
|
61
63
|
this.collectProcessHandler(instance, methodName, processorMeta);
|
|
64
|
+
this.collectBatchProcessHandler(instance, methodName, processorMeta);
|
|
62
65
|
this.registerEventHandler(instance, methodName, processorMeta);
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
await this.registerQueueWorkers();
|
|
69
|
+
await this.registerBatchProcessors();
|
|
66
70
|
}
|
|
67
71
|
collectProcessHandler(instance, methodName, processorMeta) {
|
|
68
72
|
var _a;
|
|
@@ -94,6 +98,35 @@ let ProcessorExplorer = ProcessorExplorer_1 = class ProcessorExplorer {
|
|
|
94
98
|
this.logger.log(`Collected @Process handler: ${instance.constructor.name}.${methodName}` +
|
|
95
99
|
(processMeta.name ? ` for job "${processMeta.name}"` : ' (default)'));
|
|
96
100
|
}
|
|
101
|
+
collectBatchProcessHandler(instance, methodName, processorMeta) {
|
|
102
|
+
var _a, _b, _c, _d, _e;
|
|
103
|
+
const batchMeta = this.reflector.get(batch_process_decorator_1.BATCH_PROCESS_METADATA, instance[methodName]);
|
|
104
|
+
if (!batchMeta || typeof batchMeta !== 'object' || 'event' in batchMeta) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const queueName = processorMeta.queueName;
|
|
108
|
+
if (this.batchProcessors.has(queueName)) {
|
|
109
|
+
this.logger.warn(`Multiple @BatchProcess handlers found for queue "${queueName}". Using first found.`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const boundMethod = instance[methodName].bind(instance);
|
|
113
|
+
const batchSize = (_a = batchMeta.batchSize) !== null && _a !== void 0 ? _a : 10;
|
|
114
|
+
this.batchProcessors.set(queueName, {
|
|
115
|
+
processor: boundMethod,
|
|
116
|
+
options: {
|
|
117
|
+
batchSize,
|
|
118
|
+
batchTimeout: (_b = batchMeta.batchTimeout) !== null && _b !== void 0 ? _b : 5000,
|
|
119
|
+
parallel: (_c = batchMeta.parallel) !== null && _c !== void 0 ? _c : true,
|
|
120
|
+
maxParallel: batchMeta.maxParallel,
|
|
121
|
+
continueOnError: (_d = batchMeta.continueOnError) !== null && _d !== void 0 ? _d : true,
|
|
122
|
+
retryFailedIndividually: (_e = batchMeta.retryFailedIndividually) !== null && _e !== void 0 ? _e : false,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
const methodNameStr = typeof methodName === 'string' ? methodName : String(methodName);
|
|
126
|
+
const batchSizeStr = typeof batchSize === 'number' ? batchSize.toString() : '10';
|
|
127
|
+
this.logger.log(`Collected @BatchProcess handler: ${instance.constructor.name}.${methodNameStr} ` +
|
|
128
|
+
`for queue "${queueName}" (batchSize: ${batchSizeStr})`);
|
|
129
|
+
}
|
|
97
130
|
mergeCircuitBreakerOptions(global, processor) {
|
|
98
131
|
if (!global && !processor) {
|
|
99
132
|
return undefined;
|
|
@@ -193,6 +226,14 @@ let ProcessorExplorer = ProcessorExplorer_1 = class ProcessorExplorer {
|
|
|
193
226
|
this.logger.log(`Registered worker for queue "${queueName}" with ${handlers.length} handler(s), concurrency: ${concurrency}`);
|
|
194
227
|
}
|
|
195
228
|
}
|
|
229
|
+
async registerBatchProcessors() {
|
|
230
|
+
for (const [queueName, config] of this.batchProcessors) {
|
|
231
|
+
const { processor, options } = config;
|
|
232
|
+
await this.queueProvider.processBatch(queueName, processor, options);
|
|
233
|
+
this.logger.log(`Registered batch processor for queue "${queueName}" ` +
|
|
234
|
+
`(batchSize: ${options.batchSize}, batchTimeout: ${options.batchTimeout}ms)`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
196
237
|
getMetricsHook() {
|
|
197
238
|
var _a;
|
|
198
239
|
if (!((_a = this.moduleOptions) === null || _a === void 0 ? void 0 : _a.options)) {
|
|
@@ -212,7 +253,8 @@ let ProcessorExplorer = ProcessorExplorer_1 = class ProcessorExplorer {
|
|
|
212
253
|
}
|
|
213
254
|
instance[methodName].call(instance, job, result);
|
|
214
255
|
}, undefined);
|
|
215
|
-
|
|
256
|
+
const eventStr = String(eventMeta.event);
|
|
257
|
+
this.logger.log(`Registered @OnQueueEvent handler: ${instance.constructor.name}.${methodName} for "${eventStr}"`);
|
|
216
258
|
}
|
|
217
259
|
resetCircuitBreaker(queueName) {
|
|
218
260
|
const circuitBreaker = this.circuitBreakers.get(queueName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.explorer.js","sourceRoot":"","sources":["../../lib/explorer/processor.explorer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAqG;AACrG,uCAA4E;AAC5E,+DAKoC;AACpC,+EAAyE;AAKzE,8DAAmF;
|
|
1
|
+
{"version":3,"file":"processor.explorer.js","sourceRoot":"","sources":["../../lib/explorer/processor.explorer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAqG;AACrG,uCAA4E;AAC5E,+DAKoC;AACpC,+EAAyE;AAKzE,8DAAmF;AAEnF,kFAA4G;AAgBrG,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAyB5B,YACmB,gBAAkC,EAClC,eAAgC,EAChC,SAAoB,EAErC,aAA8C,EAG9C,aAAmD;QAPlC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,oBAAe,GAAf,eAAe,CAAiB;QAChC,cAAS,GAAT,SAAS,CAAW;QAEpB,kBAAa,GAAb,aAAa,CAAgB;QAG7B,kBAAa,GAAb,aAAa,CAAqB;QAhCpC,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;QAK5C,kBAAa,GAIzB,IAAI,GAAG,EAAE,CAAC;QAKE,oBAAe,GAG3B,IAAI,GAAG,EAAE,CAAC;QAKE,oBAAe,GAAgC,IAAI,GAAG,EAAE,CAAC;IAWvE,CA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uB;QACrB,KAAK,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC/D,cAAc,CAAC,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oCAAoC,SAAS,GAAG,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF,CAAA;AAvbY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IA8BR,WAAA,IAAA,eAAM,EAAC,+BAAc,CAAC,CAAA;IAEtB,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,8CAAoB,CAAC,CAAA;qCANM,uBAAgB;QACjB,sBAAe;QACrB,gBAAS;GA5B5B,iBAAiB,CAub7B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IJob } from './job.interface';
|
|
2
|
+
export interface BatchJobResult<T = unknown> {
|
|
3
|
+
jobId: string;
|
|
4
|
+
success: boolean;
|
|
5
|
+
result?: T;
|
|
6
|
+
error?: Error;
|
|
7
|
+
}
|
|
8
|
+
export interface BatchResult<T = unknown> {
|
|
9
|
+
totalJobs: number;
|
|
10
|
+
successful: number;
|
|
11
|
+
failed: number;
|
|
12
|
+
results: BatchJobResult<T>[];
|
|
13
|
+
processingTimeMs: number;
|
|
14
|
+
}
|
|
15
|
+
export interface BatchProcessorOptions {
|
|
16
|
+
batchSize?: number;
|
|
17
|
+
batchTimeout?: number;
|
|
18
|
+
parallel?: boolean;
|
|
19
|
+
maxParallel?: number;
|
|
20
|
+
continueOnError?: boolean;
|
|
21
|
+
retryFailedIndividually?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type BatchProcessor<T = unknown, R = unknown> = (jobs: IJob<T>[], options: BatchProcessorOptions) => Promise<BatchResult<R>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.interface.js","sourceRoot":"","sources":["../../lib/interface/batch.interface.ts"],"names":[],"mappings":""}
|
package/dist/interface/index.js
CHANGED
|
@@ -19,4 +19,5 @@ __exportStar(require("./queue-provider.interface"), exports);
|
|
|
19
19
|
__exportStar(require("./queue-options.interface"), exports);
|
|
20
20
|
__exportStar(require("./idempotency-store.interface"), exports);
|
|
21
21
|
__exportStar(require("./health.interface"), exports);
|
|
22
|
+
__exportStar(require("./batch.interface"), exports);
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/interface/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,6DAA2C;AAC3C,4DAA0C;AAC1C,gEAA8C;AAC9C,qDAAmC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/interface/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,6DAA2C;AAC3C,4DAA0C;AAC1C,gEAA8C;AAC9C,qDAAmC;AACnC,oDAAkC"}
|
|
@@ -61,15 +61,7 @@ export interface RabbitMQOptions {
|
|
|
61
61
|
idempotency?: IdempotencyStoreOptions;
|
|
62
62
|
metrics?: QueueMetrics;
|
|
63
63
|
}
|
|
64
|
-
export
|
|
65
|
-
host: string;
|
|
66
|
-
port: number;
|
|
67
|
-
password?: string;
|
|
68
|
-
db?: number;
|
|
69
|
-
keyPrefix?: string;
|
|
70
|
-
tls?: boolean;
|
|
71
|
-
}
|
|
72
|
-
export type QueueProviderOptions = BullMQOptions | KafkaQueueOptions | RabbitMQOptions | RedisPubSubOptions;
|
|
64
|
+
export type QueueProviderOptions = BullMQOptions | KafkaQueueOptions | RabbitMQOptions;
|
|
73
65
|
export interface QueueModuleOptions extends MultiInstanceOptions {
|
|
74
66
|
isGlobal?: boolean;
|
|
75
67
|
provider: QueueProviderType;
|
|
@@ -4,6 +4,7 @@ import { QueueEvent } from '../enum/queue-event.enum';
|
|
|
4
4
|
import { IJob, JobOptions, ProcessorOptions } from './job.interface';
|
|
5
5
|
import { HealthCheckResult } from './health.interface';
|
|
6
6
|
import { ShutdownOptions } from '../utils/errors';
|
|
7
|
+
import { BatchProcessor, BatchProcessorOptions } from './batch.interface';
|
|
7
8
|
export interface IQueueProvider {
|
|
8
9
|
readonly type: QueueProviderType;
|
|
9
10
|
add<T>(queueName: string, jobName: string, data: T, opts?: JobOptions): Promise<IJob<T>>;
|
|
@@ -13,6 +14,12 @@ export interface IQueueProvider {
|
|
|
13
14
|
opts?: JobOptions;
|
|
14
15
|
}>): Promise<IJob<T>[]>;
|
|
15
16
|
process<T>(queueName: string, processor: (job: IJob<T>) => Promise<any>, options?: ProcessorOptions): Promise<void | boolean>;
|
|
17
|
+
processBatch<T, R>(queueName: string, processor: BatchProcessor<T, R>, options?: BatchProcessorOptions): Promise<void>;
|
|
18
|
+
addBatch<T>(queueName: string, jobs: Array<{
|
|
19
|
+
name: string;
|
|
20
|
+
data: T;
|
|
21
|
+
opts?: JobOptions;
|
|
22
|
+
}>, batchId?: string): Promise<IJob<T>[]>;
|
|
16
23
|
getJob<T>(queueName: string, jobId: string): Promise<IJob<T> | null>;
|
|
17
24
|
getJobs(queueName: string, status: JobStatus[], start?: number, end?: number): Promise<IJob[]>;
|
|
18
25
|
removeJob(queueName: string, jobId: string): Promise<void>;
|
|
@@ -38,6 +45,12 @@ export declare abstract class QueueProvider implements IQueueProvider {
|
|
|
38
45
|
opts?: JobOptions;
|
|
39
46
|
}>): Promise<IJob<T>[]>;
|
|
40
47
|
abstract process<T>(queueName: string, processor: (job: IJob<T>) => Promise<any>, options?: ProcessorOptions): Promise<void | boolean>;
|
|
48
|
+
abstract processBatch<T, R>(queueName: string, processor: BatchProcessor<T, R>, options?: BatchProcessorOptions): Promise<void>;
|
|
49
|
+
abstract addBatch<T>(queueName: string, jobs: Array<{
|
|
50
|
+
name: string;
|
|
51
|
+
data: T;
|
|
52
|
+
opts?: JobOptions;
|
|
53
|
+
}>, batchId?: string): Promise<IJob<T>[]>;
|
|
41
54
|
abstract getJob<T>(queueName: string, jobId: string): Promise<IJob<T> | null>;
|
|
42
55
|
abstract getJobs(queueName: string, status: JobStatus[], start?: number, end?: number): Promise<IJob[]>;
|
|
43
56
|
abstract removeJob(queueName: string, jobId: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue-provider.interface.js","sourceRoot":"","sources":["../../lib/interface/queue-provider.interface.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"queue-provider.interface.js","sourceRoot":"","sources":["../../lib/interface/queue-provider.interface.ts"],"names":[],"mappings":";;;AA+IA,MAAsB,aAAa;CAwElC;AAxED,sCAwEC"}
|
|
@@ -6,7 +6,6 @@ const provider_enum_1 = require("../enum/provider.enum");
|
|
|
6
6
|
const bullmq_provider_1 = require("../provider/bullmq/bullmq.provider");
|
|
7
7
|
const kafka_provider_1 = require("../provider/kafka/kafka.provider");
|
|
8
8
|
const rabbitmq_provider_1 = require("../provider/rabbitmq/rabbitmq.provider");
|
|
9
|
-
const redis_pubsub_provider_1 = require("../provider/redis-pubsub/redis-pubsub.provider");
|
|
10
9
|
const queue_module_definition_1 = require("./queue.module-definition");
|
|
11
10
|
const in_memory_idempotency_store_1 = require("../store/in-memory-idempotency.store");
|
|
12
11
|
function createQueueProvider() {
|
|
@@ -40,8 +39,6 @@ function createQueueProvider() {
|
|
|
40
39
|
return new kafka_provider_1.KafkaQueueProvider(options.options);
|
|
41
40
|
case provider_enum_1.QueueProviderType.RABBITMQ:
|
|
42
41
|
return new rabbitmq_provider_1.RabbitMQQueueProvider(options.options);
|
|
43
|
-
case provider_enum_1.QueueProviderType.REDIS_PUBSUB:
|
|
44
|
-
return new redis_pubsub_provider_1.RedisPubSubProvider(options.options);
|
|
45
42
|
case provider_enum_1.QueueProviderType.CUSTOM:
|
|
46
43
|
if (!options.customProvider) {
|
|
47
44
|
throw new Error('Custom provider type requires a customProvider class to be specified');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.provider.js","sourceRoot":"","sources":["../../lib/module/queue.provider.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"queue.provider.js","sourceRoot":"","sources":["../../lib/module/queue.provider.ts"],"names":[],"mappings":";;AAmBA,kDAsDC;AAxED,+DAA4D;AAC5D,yDAA0D;AAQ1D,wEAAoE;AACpE,qEAAsE;AACtE,8EAA+E;AAC/E,uEAAiE;AACjE,sFAAgF;AAKhF,SAAgB,mBAAmB;IACjC,OAAO;QACL,OAAO,EAAE,+BAAc;QACvB,UAAU,EAAE,CAAC,OAA2B,EAAiB,EAAE;YAEzD,IAAI,OAAO,CAAC,sBAAsB,EAAE,CAAC;gBACnC,MAAM,eAAe,GAAG,OAAO,CAAC,OAGf,CAAC;gBAGlB,IAAI,aAAa,IAAI,eAAe,EAAE,CAAC;oBACrC,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;wBACjC,eAAe,CAAC,WAAW,GAAG;4BAC5B,OAAO,EAAE,IAAI;4BACb,KAAK,EAAE,IAAI,sDAAwB,EAAE;4BACrC,OAAO,EAAE,KAAM;4BACf,YAAY,EAAE,OAAQ;yBACvB,CAAC;oBACJ,CAAC;yBAAM,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;wBAC9C,eAAe,CAAC,WAAW,GAAG;4BAC5B,GAAG,eAAe,CAAC,WAAW;4BAC9B,OAAO,EAAE,IAAI;4BACb,KAAK,EAAE,IAAI,sDAAwB,EAAE;yBACtC,CAAC;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC;YAED,QAAQ,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACzB,KAAK,iCAAiB,CAAC,MAAM;oBAC3B,OAAO,IAAI,gCAAc,CAAC,OAAO,CAAC,OAAwB,CAAC,CAAC;gBAE9D,KAAK,iCAAiB,CAAC,KAAK;oBAC1B,OAAO,IAAI,mCAAkB,CAAC,OAAO,CAAC,OAA4B,CAAC,CAAC;gBAEtE,KAAK,iCAAiB,CAAC,QAAQ;oBAC7B,OAAO,IAAI,yCAAqB,CAAC,OAAO,CAAC,OAA0B,CAAC,CAAC;gBAEvE,KAAK,iCAAiB,CAAC,MAAM;oBAC3B,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;wBAC5B,MAAM,IAAI,KAAK,CACb,sEAAsE,CACvE,CAAC;oBACJ,CAAC;oBACD,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAErD;oBACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;YACxE,CAAC;QACH,CAAC;QACD,MAAM,EAAE,CAAC,8CAAoB,CAAC;KAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -6,6 +6,7 @@ import { IJob, JobOptions, ProcessorOptions } from '../../interface/job.interfac
|
|
|
6
6
|
import { QueueProvider } from '../../interface/queue-provider.interface';
|
|
7
7
|
import { BullMQOptions } from '../../interface/queue-options.interface';
|
|
8
8
|
import { HealthCheckResult } from '../../interface/health.interface';
|
|
9
|
+
import { BatchProcessor, BatchProcessorOptions } from '../../interface/batch.interface';
|
|
9
10
|
export declare class BullMQProvider extends QueueProvider {
|
|
10
11
|
private readonly options;
|
|
11
12
|
private readonly logger;
|
|
@@ -18,6 +19,8 @@ export declare class BullMQProvider extends QueueProvider {
|
|
|
18
19
|
protected readonly eventListeners: Map<string, Map<QueueEvent, Array<(job: IJob, result?: any) => void>>>;
|
|
19
20
|
private readonly listenerRegistry;
|
|
20
21
|
private readonly metrics?;
|
|
22
|
+
private readonly batchAccumulators;
|
|
23
|
+
private readonly batchTimers;
|
|
21
24
|
readonly type = QueueProviderType.BULLMQ;
|
|
22
25
|
constructor(options: BullMQOptions);
|
|
23
26
|
private getQueue;
|
|
@@ -32,6 +35,12 @@ export declare class BullMQProvider extends QueueProvider {
|
|
|
32
35
|
opts?: JobOptions;
|
|
33
36
|
}>): Promise<IJob<T>[]>;
|
|
34
37
|
process<T>(queueName: string, processor: (job: IJob<T>) => Promise<any>, options?: ProcessorOptions): Promise<boolean>;
|
|
38
|
+
processBatch<T, R>(queueName: string, processor: BatchProcessor<T, R>, options?: BatchProcessorOptions): Promise<void>;
|
|
39
|
+
addBatch<T>(queueName: string, jobs: Array<{
|
|
40
|
+
name: string;
|
|
41
|
+
data: T;
|
|
42
|
+
opts?: JobOptions;
|
|
43
|
+
}>, batchId?: string): Promise<IJob<T>[]>;
|
|
35
44
|
getJob<T>(queueName: string, jobId: string): Promise<IJob<T> | null>;
|
|
36
45
|
getJobs(queueName: string, status: JobStatus[], start?: number, end?: number): Promise<IJob[]>;
|
|
37
46
|
private mapStatusToBullMQ;
|
|
@@ -19,6 +19,8 @@ class BullMQProvider extends queue_provider_interface_1.QueueProvider {
|
|
|
19
19
|
this.queueEvents = new Map();
|
|
20
20
|
this.eventListeners = new Map();
|
|
21
21
|
this.listenerRegistry = new Map();
|
|
22
|
+
this.batchAccumulators = new Map();
|
|
23
|
+
this.batchTimers = new Map();
|
|
22
24
|
this.type = provider_enum_1.QueueProviderType.BULLMQ;
|
|
23
25
|
this.connection = {
|
|
24
26
|
host: options.connection.host,
|
|
@@ -234,6 +236,103 @@ class BullMQProvider extends queue_provider_interface_1.QueueProvider {
|
|
|
234
236
|
this.logger.log(`Worker started for queue: ${queueName}${(options === null || options === void 0 ? void 0 : options.name) ? ` (${options.name})` : ''}`);
|
|
235
237
|
return true;
|
|
236
238
|
}
|
|
239
|
+
async processBatch(queueName, processor, options) {
|
|
240
|
+
const { batchSize = 10, batchTimeout = 5000, parallel = true, maxParallel, continueOnError = true, retryFailedIndividually = false, } = options || {};
|
|
241
|
+
const workerKey = `${queueName}:batch`;
|
|
242
|
+
if (this.workers.has(workerKey)) {
|
|
243
|
+
throw new errors_1.QueueError(`Batch worker already exists for ${queueName}. Cannot register duplicate batch processor.`, 'WORKER_EXISTS', queueName);
|
|
244
|
+
}
|
|
245
|
+
const accumulatorKey = queueName;
|
|
246
|
+
this.batchAccumulators.set(accumulatorKey, []);
|
|
247
|
+
const processBatchFn = async () => {
|
|
248
|
+
const timer = this.batchTimers.get(accumulatorKey);
|
|
249
|
+
if (timer) {
|
|
250
|
+
clearTimeout(timer);
|
|
251
|
+
this.batchTimers.delete(accumulatorKey);
|
|
252
|
+
}
|
|
253
|
+
const batch = this.batchAccumulators.get(accumulatorKey) || [];
|
|
254
|
+
if (batch.length === 0)
|
|
255
|
+
return;
|
|
256
|
+
this.batchAccumulators.set(accumulatorKey, []);
|
|
257
|
+
const jobs = batch.map((job) => this.mapJob(job));
|
|
258
|
+
const startTime = Date.now();
|
|
259
|
+
try {
|
|
260
|
+
const result = await processor(jobs, options || {});
|
|
261
|
+
for (let i = 0; i < batch.length; i++) {
|
|
262
|
+
const jobResult = result.results[i];
|
|
263
|
+
if (jobResult.success) {
|
|
264
|
+
await batch[i].moveToCompleted(jobResult.result, batch[i].token);
|
|
265
|
+
}
|
|
266
|
+
else if (retryFailedIndividually && jobResult.error) {
|
|
267
|
+
await batch[i].moveToFailed(jobResult.error, batch[i].token);
|
|
268
|
+
}
|
|
269
|
+
else if (!continueOnError && jobResult.error) {
|
|
270
|
+
await batch[i].moveToFailed(jobResult.error, batch[i].token);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
await batch[i].moveToCompleted(undefined, batch[i].token);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const duration = Date.now() - startTime;
|
|
277
|
+
this.logger.debug(`Batch processed: ${result.successful}/${result.totalJobs} succeeded in ${duration}ms`);
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
this.logger.error(`Batch processing failed: ${error.message}`);
|
|
281
|
+
for (const job of batch) {
|
|
282
|
+
await job.moveToFailed(error, job.token);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
const worker = new bullmq_1.Worker(queueName, async (job) => {
|
|
287
|
+
const accumulator = this.batchAccumulators.get(accumulatorKey) || [];
|
|
288
|
+
accumulator.push(job);
|
|
289
|
+
this.batchAccumulators.set(accumulatorKey, accumulator);
|
|
290
|
+
if (accumulator.length >= batchSize) {
|
|
291
|
+
await processBatchFn();
|
|
292
|
+
}
|
|
293
|
+
else if (!this.batchTimers.has(accumulatorKey)) {
|
|
294
|
+
const timer = setTimeout(() => {
|
|
295
|
+
processBatchFn().catch((err) => {
|
|
296
|
+
this.logger.error(`Batch timeout processing failed: ${err.message}`);
|
|
297
|
+
});
|
|
298
|
+
}, batchTimeout);
|
|
299
|
+
this.batchTimers.set(accumulatorKey, timer);
|
|
300
|
+
}
|
|
301
|
+
return undefined;
|
|
302
|
+
}, {
|
|
303
|
+
...this.mapWorkerOptions({ concurrency: batchSize }),
|
|
304
|
+
});
|
|
305
|
+
worker.on('error', (error) => {
|
|
306
|
+
this.logger.error(`Batch worker error: ${error.message}`);
|
|
307
|
+
});
|
|
308
|
+
this.workers.set(workerKey, worker);
|
|
309
|
+
this.logger.log(`Batch worker started for queue: ${queueName} (batchSize: ${batchSize})`);
|
|
310
|
+
}
|
|
311
|
+
async addBatch(queueName, jobs, batchId) {
|
|
312
|
+
const queue = this.getQueue(queueName);
|
|
313
|
+
const bulkJobs = jobs.map((j) => {
|
|
314
|
+
var _a;
|
|
315
|
+
const sanitizedCorrelationId = (0, errors_1.sanitizeCorrelationId)((_a = j.opts) === null || _a === void 0 ? void 0 : _a.correlationId);
|
|
316
|
+
const enrichedData = sanitizedCorrelationId
|
|
317
|
+
? { ...j.data, __correlationId: sanitizedCorrelationId }
|
|
318
|
+
: j.data;
|
|
319
|
+
const opts = { ...this.defaultJobOptions, ...j.opts };
|
|
320
|
+
if (batchId) {
|
|
321
|
+
opts.headers = {
|
|
322
|
+
...opts.headers,
|
|
323
|
+
'x-batch-id': batchId,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
return {
|
|
327
|
+
name: j.name,
|
|
328
|
+
data: enrichedData,
|
|
329
|
+
opts: this.mapJobOptions(opts),
|
|
330
|
+
};
|
|
331
|
+
});
|
|
332
|
+
const addedJobs = await queue.addBulk(bulkJobs);
|
|
333
|
+
this.logger.debug(`${addedJobs.length} jobs added to batch queue ${queueName}${batchId ? ` (batch: ${batchId})` : ''}`);
|
|
334
|
+
return addedJobs.map((job) => this.mapJob(job));
|
|
335
|
+
}
|
|
237
336
|
async getJob(queueName, jobId) {
|
|
238
337
|
const queue = this.getQueue(queueName);
|
|
239
338
|
const job = await queue.getJob(jobId);
|
|
@@ -366,6 +465,11 @@ class BullMQProvider extends queue_provider_interface_1.QueueProvider {
|
|
|
366
465
|
const timeout = (_a = options.timeout) !== null && _a !== void 0 ? _a : 30000;
|
|
367
466
|
const force = (_b = options.force) !== null && _b !== void 0 ? _b : false;
|
|
368
467
|
this.logger.log(`Closing BullMQ connections (timeout: ${timeout}ms, force: ${force})...`);
|
|
468
|
+
for (const timer of this.batchTimers.values()) {
|
|
469
|
+
clearTimeout(timer);
|
|
470
|
+
}
|
|
471
|
+
this.batchTimers.clear();
|
|
472
|
+
this.batchAccumulators.clear();
|
|
369
473
|
const closeWithTimeout = async (name, closeFn, type) => {
|
|
370
474
|
try {
|
|
371
475
|
if (force) {
|