@lyrolab/nest-shared 1.1.1 → 1.3.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/CHANGELOG.md +3 -3
- package/dist/queue/decorators/queue.decorator.d.ts +5 -1
- package/dist/queue/decorators/queue.decorator.js.map +1 -1
- package/dist/queue/index.d.ts +1 -0
- package/dist/queue/index.js +1 -0
- package/dist/queue/index.js.map +1 -1
- package/dist/queue/interfaces/queue-options.interface.d.ts +13 -0
- package/dist/queue/interfaces/queue-options.interface.js +3 -0
- package/dist/queue/interfaces/queue-options.interface.js.map +1 -0
- package/dist/queue/processors/queue.processor.d.ts +9 -3
- package/dist/queue/processors/queue.processor.js +56 -10
- package/dist/queue/processors/queue.processor.js.map +1 -1
- package/dist/queue/queue.constants.d.ts +1 -0
- package/dist/queue/queue.constants.js +2 -1
- package/dist/queue/queue.constants.js.map +1 -1
- package/dist/queue/shared-queue.module.d.ts +6 -0
- package/dist/queue/shared-queue.module.js +71 -9
- package/dist/queue/shared-queue.module.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
# [1.3.0](https://github.com/lyrolab/nest-shared/compare/v1.2.0...v1.3.0) (2025-04-22)
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
###
|
|
4
|
+
### Features
|
|
5
5
|
|
|
6
|
-
*
|
|
6
|
+
* configure queue concurrency ([a1b7a4f](https://github.com/lyrolab/nest-shared/commit/a1b7a4fc420689391638e4a4bca8b77d915adc87))
|
|
7
7
|
|
|
8
8
|
## [1.0.1](https://github.com/lyrolab/nest-shared/compare/v1.0.0...v1.0.1) (2025-04-10)
|
|
9
9
|
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type JobProcessorMetadata = {
|
|
2
|
+
name: string;
|
|
3
|
+
cron?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const JobProcessor: import("@nestjs/core").DiscoverableDecorator<string | JobProcessorMetadata>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.decorator.js","sourceRoot":"","sources":["../../../src/queue/decorators/queue.decorator.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;
|
|
1
|
+
{"version":3,"file":"queue.decorator.js","sourceRoot":"","sources":["../../../src/queue/decorators/queue.decorator.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAelC,QAAA,YAAY,GAAG,uBAAgB,CAAC,eAAe,EAEzD,CAAA"}
|
package/dist/queue/index.d.ts
CHANGED
package/dist/queue/index.js
CHANGED
|
@@ -18,4 +18,5 @@ __exportStar(require("./shared-queue.module"), exports);
|
|
|
18
18
|
__exportStar(require("./services/queue.service"), exports);
|
|
19
19
|
__exportStar(require("./models/job-processor-interface"), exports);
|
|
20
20
|
__exportStar(require("./decorators/queue.decorator"), exports);
|
|
21
|
+
__exportStar(require("./interfaces/queue-options.interface"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/dist/queue/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/queue/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqC;AACrC,2DAAwC;AACxC,mEAAgD;AAChD,+DAA4C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/queue/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqC;AACrC,2DAAwC;AACxC,mEAAgD;AAChD,+DAA4C;AAC5C,uEAAoD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ModuleMetadata, Type } from "@nestjs/common";
|
|
2
|
+
export interface QueueModuleOptions {
|
|
3
|
+
concurrency?: number;
|
|
4
|
+
}
|
|
5
|
+
export interface QueueModuleAsyncOptions extends Pick<ModuleMetadata, "imports"> {
|
|
6
|
+
useFactory?: (...args: any[]) => Promise<QueueModuleOptions> | QueueModuleOptions;
|
|
7
|
+
inject?: any[];
|
|
8
|
+
useClass?: Type<QueueOptionsFactory>;
|
|
9
|
+
useExisting?: Type<QueueOptionsFactory>;
|
|
10
|
+
}
|
|
11
|
+
export interface QueueOptionsFactory {
|
|
12
|
+
createQueueOptions(): Promise<QueueModuleOptions> | QueueModuleOptions;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-options.interface.js","sourceRoot":"","sources":["../../../src/queue/interfaces/queue-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { WorkerHost } from "@nestjs/bullmq";
|
|
2
2
|
import { DiscoveryService } from "@nestjs/core";
|
|
3
3
|
import { Job, Queue } from "bullmq";
|
|
4
|
-
|
|
4
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
5
|
+
import { QueueModuleOptions } from "../interfaces/queue-options.interface";
|
|
6
|
+
export declare class QueueProcessor extends WorkerHost implements OnModuleInit {
|
|
5
7
|
private readonly discoveryService;
|
|
6
8
|
private readonly queue;
|
|
7
|
-
|
|
9
|
+
private readonly options?;
|
|
10
|
+
constructor(discoveryService: DiscoveryService, queue: Queue, options?: QueueModuleOptions | undefined);
|
|
11
|
+
onModuleInit(): Promise<void>;
|
|
8
12
|
process(job: Job): Promise<void>;
|
|
9
|
-
private
|
|
13
|
+
private getJobConfigurations;
|
|
14
|
+
private scheduleJobs;
|
|
10
15
|
private shouldProcessJob;
|
|
16
|
+
private getJobProcessorByName;
|
|
11
17
|
}
|
|
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
+
var QueueProcessor_1;
|
|
14
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
16
|
exports.QueueProcessor = void 0;
|
|
16
17
|
const bullmq_1 = require("@nestjs/bullmq");
|
|
@@ -18,16 +19,26 @@ const core_1 = require("@nestjs/core");
|
|
|
18
19
|
const bullmq_2 = require("bullmq");
|
|
19
20
|
const queue_decorator_1 = require("../decorators/queue.decorator");
|
|
20
21
|
const queue_constants_1 = require("../queue.constants");
|
|
21
|
-
|
|
22
|
+
const common_1 = require("@nestjs/common");
|
|
23
|
+
let QueueProcessor = QueueProcessor_1 = class QueueProcessor extends bullmq_1.WorkerHost {
|
|
22
24
|
discoveryService;
|
|
23
25
|
queue;
|
|
24
|
-
|
|
26
|
+
options;
|
|
27
|
+
constructor(discoveryService, queue, options) {
|
|
25
28
|
super();
|
|
26
29
|
this.discoveryService = discoveryService;
|
|
27
30
|
this.queue = queue;
|
|
31
|
+
this.options = options;
|
|
32
|
+
if (this.options?.concurrency) {
|
|
33
|
+
(0, common_1.SetMetadata)("bullmq:worker_metadata", this.options)(QueueProcessor_1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async onModuleInit() {
|
|
37
|
+
const jobConfigs = this.getJobConfigurations();
|
|
38
|
+
await this.scheduleJobs(jobConfigs);
|
|
28
39
|
}
|
|
29
40
|
async process(job) {
|
|
30
|
-
const jobProcessor = this.
|
|
41
|
+
const jobProcessor = this.getJobProcessorByName(job.name);
|
|
31
42
|
if (!jobProcessor)
|
|
32
43
|
return;
|
|
33
44
|
const shouldProcess = await this.shouldProcessJob(job);
|
|
@@ -40,24 +51,59 @@ let QueueProcessor = class QueueProcessor extends bullmq_1.WorkerHost {
|
|
|
40
51
|
console.error(error);
|
|
41
52
|
}
|
|
42
53
|
}
|
|
43
|
-
|
|
54
|
+
getJobConfigurations() {
|
|
44
55
|
return this.discoveryService
|
|
45
56
|
.getProviders({ metadataKey: queue_decorator_1.JobProcessor.KEY })
|
|
46
|
-
.
|
|
57
|
+
.map((provider) => {
|
|
58
|
+
const metadata = this.discoveryService.getMetadataByDecorator(queue_decorator_1.JobProcessor, provider);
|
|
59
|
+
if (!metadata)
|
|
60
|
+
return null;
|
|
61
|
+
if (typeof metadata === "string") {
|
|
62
|
+
return { name: metadata };
|
|
63
|
+
}
|
|
64
|
+
return { name: metadata.name, cron: metadata.cron };
|
|
65
|
+
})
|
|
66
|
+
.filter((job) => job !== null);
|
|
67
|
+
}
|
|
68
|
+
async scheduleJobs(jobConfigs) {
|
|
69
|
+
const schedulingPromises = jobConfigs
|
|
70
|
+
.filter((job) => job.cron)
|
|
71
|
+
.map(async ({ name, cron }) => {
|
|
72
|
+
const existingSchedulers = await this.queue.getJobSchedulers();
|
|
73
|
+
const outdatedSchedulers = existingSchedulers.filter((scheduler) => scheduler.name === name && scheduler.pattern !== cron);
|
|
74
|
+
await Promise.allSettled(outdatedSchedulers.map((scheduler) => this.queue.removeJobScheduler(scheduler.key)));
|
|
75
|
+
await this.queue.upsertJobScheduler(name, { pattern: cron }, { name });
|
|
76
|
+
});
|
|
77
|
+
await Promise.all(schedulingPromises);
|
|
47
78
|
}
|
|
48
79
|
async shouldProcessJob(job) {
|
|
49
80
|
if (!job.repeatJobKey)
|
|
50
81
|
return true;
|
|
51
82
|
const activeJobs = await this.queue.getActive();
|
|
52
|
-
const
|
|
53
|
-
return
|
|
83
|
+
const activeJobsOfSameType = activeJobs.filter((activeJob) => activeJob.name === job.name && activeJob.id !== job.id);
|
|
84
|
+
return activeJobsOfSameType.length === 0;
|
|
85
|
+
}
|
|
86
|
+
getJobProcessorByName(jobName) {
|
|
87
|
+
const providerWithProcessor = this.discoveryService
|
|
88
|
+
.getProviders({ metadataKey: queue_decorator_1.JobProcessor.KEY })
|
|
89
|
+
.find((provider) => {
|
|
90
|
+
const metadata = this.discoveryService.getMetadataByDecorator(queue_decorator_1.JobProcessor, provider);
|
|
91
|
+
if (!metadata)
|
|
92
|
+
return false;
|
|
93
|
+
const name = typeof metadata === "string" ? metadata : metadata.name;
|
|
94
|
+
return name === jobName;
|
|
95
|
+
});
|
|
96
|
+
return providerWithProcessor?.instance ?? null;
|
|
54
97
|
}
|
|
55
98
|
};
|
|
56
99
|
exports.QueueProcessor = QueueProcessor;
|
|
57
|
-
exports.QueueProcessor = QueueProcessor = __decorate([
|
|
58
|
-
(0,
|
|
100
|
+
exports.QueueProcessor = QueueProcessor = QueueProcessor_1 = __decorate([
|
|
101
|
+
(0, common_1.Injectable)(),
|
|
102
|
+
(0, bullmq_1.Processor)(queue_constants_1.DEFAULT_QUEUE),
|
|
59
103
|
__param(1, (0, bullmq_1.InjectQueue)(queue_constants_1.DEFAULT_QUEUE)),
|
|
104
|
+
__param(2, (0, common_1.Optional)()),
|
|
105
|
+
__param(2, (0, common_1.Inject)(queue_constants_1.QUEUE_MODULE_OPTIONS)),
|
|
60
106
|
__metadata("design:paramtypes", [core_1.DiscoveryService,
|
|
61
|
-
bullmq_2.Queue])
|
|
107
|
+
bullmq_2.Queue, Object])
|
|
62
108
|
], QueueProcessor);
|
|
63
109
|
//# sourceMappingURL=queue.processor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.processor.js","sourceRoot":"","sources":["../../../src/queue/processors/queue.processor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"queue.processor.js","sourceRoot":"","sources":["../../../src/queue/processors/queue.processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAmE;AACnE,uCAA+C;AAC/C,mCAAmC;AAEnC,mEAA4D;AAC5D,wDAAwE;AACxE,2CAMuB;AAKhB,IAAM,cAAc,sBAApB,MAAM,cAAe,SAAQ,mBAAU;IAEzB;IAC4B;IAG5B;IALnB,YACmB,gBAAkC,EACN,KAAY,EAGxC,OAA4B;QAE7C,KAAK,EAAE,CAAA;QANU,qBAAgB,GAAhB,gBAAgB,CAAkB;QACN,UAAK,GAAL,KAAK,CAAO;QAGxC,YAAO,GAAP,OAAO,CAAqB;QAI7C,IAAI,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC;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QUEUE = "default";
|
|
5
|
+
exports.QUEUE_MODULE_OPTIONS = "QUEUE_MODULE_OPTIONS";
|
|
5
6
|
//# sourceMappingURL=queue.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.constants.js","sourceRoot":"","sources":["../../src/queue/queue.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"queue.constants.js","sourceRoot":"","sources":["../../src/queue/queue.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,SAAS,CAAA;AACzB,QAAA,oBAAoB,GAAG,sBAAsB,CAAA"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { QueueModuleAsyncOptions, QueueModuleOptions } from "./interfaces/queue-options.interface";
|
|
1
3
|
export declare class SharedQueueModule {
|
|
4
|
+
static forRoot(options?: QueueModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: QueueModuleAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncProviders;
|
|
7
|
+
private static createAsyncOptionsProvider;
|
|
2
8
|
}
|
|
@@ -5,24 +5,86 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var SharedQueueModule_1;
|
|
8
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
10
|
exports.SharedQueueModule = void 0;
|
|
10
11
|
const bullmq_1 = require("@nestjs/bullmq");
|
|
11
12
|
const common_1 = require("@nestjs/common");
|
|
12
13
|
const core_1 = require("@nestjs/core");
|
|
14
|
+
const queue_controller_1 = require("./controllers/queue.controller");
|
|
13
15
|
const queue_processor_1 = require("./processors/queue.processor");
|
|
14
16
|
const queue_constants_1 = require("./queue.constants");
|
|
15
17
|
const queue_service_1 = require("./services/queue.service");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
let SharedQueueModule = SharedQueueModule_1 = class SharedQueueModule {
|
|
19
|
+
static forRoot(options = {}) {
|
|
20
|
+
return {
|
|
21
|
+
module: SharedQueueModule_1,
|
|
22
|
+
global: true,
|
|
23
|
+
imports: [
|
|
24
|
+
bullmq_1.BullModule.registerQueue({ name: queue_constants_1.DEFAULT_QUEUE }),
|
|
25
|
+
core_1.DiscoveryModule,
|
|
26
|
+
],
|
|
27
|
+
providers: [
|
|
28
|
+
{
|
|
29
|
+
provide: queue_constants_1.QUEUE_MODULE_OPTIONS,
|
|
30
|
+
useValue: options,
|
|
31
|
+
},
|
|
32
|
+
queue_service_1.QueueService,
|
|
33
|
+
queue_processor_1.QueueProcessor,
|
|
34
|
+
],
|
|
35
|
+
exports: [queue_service_1.QueueService],
|
|
36
|
+
controllers: [queue_controller_1.QueueController],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
static forRootAsync(options) {
|
|
40
|
+
return {
|
|
41
|
+
module: SharedQueueModule_1,
|
|
42
|
+
global: true,
|
|
43
|
+
imports: [
|
|
44
|
+
bullmq_1.BullModule.registerQueue({ name: queue_constants_1.DEFAULT_QUEUE }),
|
|
45
|
+
core_1.DiscoveryModule,
|
|
46
|
+
...(options.imports || []),
|
|
47
|
+
],
|
|
48
|
+
providers: [
|
|
49
|
+
...this.createAsyncProviders(options),
|
|
50
|
+
queue_service_1.QueueService,
|
|
51
|
+
queue_processor_1.QueueProcessor,
|
|
52
|
+
],
|
|
53
|
+
exports: [queue_service_1.QueueService],
|
|
54
|
+
controllers: [queue_controller_1.QueueController],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
static createAsyncProviders(options) {
|
|
58
|
+
if (options.useExisting || options.useFactory) {
|
|
59
|
+
return [this.createAsyncOptionsProvider(options)];
|
|
60
|
+
}
|
|
61
|
+
return [
|
|
62
|
+
this.createAsyncOptionsProvider(options),
|
|
63
|
+
{
|
|
64
|
+
provide: options.useClass,
|
|
65
|
+
useClass: options.useClass,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
static createAsyncOptionsProvider(options) {
|
|
70
|
+
if (options.useFactory) {
|
|
71
|
+
return {
|
|
72
|
+
provide: queue_constants_1.QUEUE_MODULE_OPTIONS,
|
|
73
|
+
useFactory: options.useFactory,
|
|
74
|
+
inject: options.inject || [],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
provide: queue_constants_1.QUEUE_MODULE_OPTIONS,
|
|
79
|
+
useFactory: async (optionsFactory) => {
|
|
80
|
+
return optionsFactory.createQueueOptions();
|
|
81
|
+
},
|
|
82
|
+
inject: [options.useExisting || options.useClass],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
18
85
|
};
|
|
19
86
|
exports.SharedQueueModule = SharedQueueModule;
|
|
20
|
-
exports.SharedQueueModule = SharedQueueModule = __decorate([
|
|
21
|
-
(0, common_1.Module)({
|
|
22
|
-
imports: [bullmq_1.BullModule.registerQueue({ name: queue_constants_1.DEFAULT_QUEUE }), core_1.DiscoveryModule],
|
|
23
|
-
providers: [queue_service_1.QueueService, queue_processor_1.QueueProcessor],
|
|
24
|
-
exports: [queue_service_1.QueueService],
|
|
25
|
-
controllers: [queue_controller_1.QueueController],
|
|
26
|
-
})
|
|
87
|
+
exports.SharedQueueModule = SharedQueueModule = SharedQueueModule_1 = __decorate([
|
|
88
|
+
(0, common_1.Module)({})
|
|
27
89
|
], SharedQueueModule);
|
|
28
90
|
//# sourceMappingURL=shared-queue.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-queue.module.js","sourceRoot":"","sources":["../../src/queue/shared-queue.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared-queue.module.js","sourceRoot":"","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