@seta-labs/nestjs-bullmq 0.2.0 → 0.2.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/dist/bullmq.constants.d.ts +2 -2
- package/dist/bullmq.constants.js +2 -2
- package/dist/bullmq.constants.js.map +1 -1
- package/dist/metrics/queue-metrics.module.js +21 -8
- package/dist/metrics/queue-metrics.module.js.map +1 -1
- package/dist/metrics/queue-metrics.service.d.ts +8 -3
- package/dist/metrics/queue-metrics.service.js +15 -9
- package/dist/metrics/queue-metrics.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const QUEUE_EVENTS_OPTIONS: unique symbol;
|
|
2
2
|
export declare const QUEUE_METRICS_OPTIONS: unique symbol;
|
|
3
|
-
/**
|
|
4
|
-
export declare const
|
|
3
|
+
/** Opens the `Queue` of one configured name for `/metrics`. */
|
|
4
|
+
export declare const QUEUE_METRICS_QUEUE_FACTORY: unique symbol;
|
|
5
5
|
export declare const DEFAULT_SUMMARY_INTERVAL_MS = 60000;
|
|
6
6
|
export declare const DEFAULT_METRICS_TIMEOUT_MS = 5000;
|
|
7
7
|
/** Prometheus text exposition format, version 0.0.4. */
|
package/dist/bullmq.constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const QUEUE_EVENTS_OPTIONS = Symbol('QUEUE_EVENTS_OPTIONS');
|
|
2
2
|
export const QUEUE_METRICS_OPTIONS = Symbol('QUEUE_METRICS_OPTIONS');
|
|
3
|
-
/**
|
|
4
|
-
export const
|
|
3
|
+
/** Opens the `Queue` of one configured name for `/metrics`. */
|
|
4
|
+
export const QUEUE_METRICS_QUEUE_FACTORY = Symbol('QUEUE_METRICS_QUEUE_FACTORY');
|
|
5
5
|
export const DEFAULT_SUMMARY_INTERVAL_MS = 60_000;
|
|
6
6
|
export const DEFAULT_METRICS_TIMEOUT_MS = 5_000;
|
|
7
7
|
/** Prometheus text exposition format, version 0.0.4. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bullmq.constants.js","sourceRoot":"","sources":["../src/bullmq.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAErE
|
|
1
|
+
{"version":3,"file":"bullmq.constants.js","sourceRoot":"","sources":["../src/bullmq.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAErE,+DAA+D;AAC/D,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAEjF,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAElD,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,CAAC;AAEhD,wDAAwD;AACxD,MAAM,CAAC,MAAM,uBAAuB,GAAG,0CAA0C,CAAC"}
|
|
@@ -5,15 +5,28 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
var QueueMetricsModule_1;
|
|
8
|
-
import { Module } from '@nestjs/common';
|
|
8
|
+
import { Logger, Module } from '@nestjs/common';
|
|
9
9
|
import { Queue } from 'bullmq';
|
|
10
|
-
import { QUEUE_METRICS_OPTIONS,
|
|
10
|
+
import { QUEUE_METRICS_OPTIONS, QUEUE_METRICS_QUEUE_FACTORY } from '../bullmq.constants.js';
|
|
11
11
|
import { createQueueMetricsController } from './queue-metrics.controller.js';
|
|
12
12
|
import { QueueMetricsService } from './queue-metrics.service.js';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const logger = new Logger('QueueMetricsModule');
|
|
14
|
+
/**
|
|
15
|
+
* One `Queue` per configured name, closed by `QueueMetricsService` on
|
|
16
|
+
* shutdown. A queue without an `error` listener would turn a Redis outage
|
|
17
|
+
* into an uncaught exception: the listener only traces it, since the failed
|
|
18
|
+
* scrape already warns once per minute.
|
|
19
|
+
*/
|
|
20
|
+
const QUEUE_FACTORY_PROVIDER = {
|
|
21
|
+
provide: QUEUE_METRICS_QUEUE_FACTORY,
|
|
22
|
+
useFactory: (options) => (name) => {
|
|
23
|
+
const queue = new Queue(name, {
|
|
24
|
+
connection: options.connection,
|
|
25
|
+
prefix: options.prefix,
|
|
26
|
+
});
|
|
27
|
+
queue.on('error', (err) => logger.debug({ err, queue: name }, 'queue metrics connection failed'));
|
|
28
|
+
return queue;
|
|
29
|
+
},
|
|
17
30
|
inject: [QUEUE_METRICS_OPTIONS],
|
|
18
31
|
};
|
|
19
32
|
/**
|
|
@@ -28,7 +41,7 @@ let QueueMetricsModule = QueueMetricsModule_1 = class QueueMetricsModule {
|
|
|
28
41
|
controllers: [createQueueMetricsController(options.decorators)],
|
|
29
42
|
providers: [
|
|
30
43
|
{ provide: QUEUE_METRICS_OPTIONS, useValue: options },
|
|
31
|
-
|
|
44
|
+
QUEUE_FACTORY_PROVIDER,
|
|
32
45
|
QueueMetricsService,
|
|
33
46
|
],
|
|
34
47
|
exports: [QueueMetricsService],
|
|
@@ -46,7 +59,7 @@ let QueueMetricsModule = QueueMetricsModule_1 = class QueueMetricsModule {
|
|
|
46
59
|
useFactory: options.useFactory,
|
|
47
60
|
inject: options.inject ?? [],
|
|
48
61
|
},
|
|
49
|
-
|
|
62
|
+
QUEUE_FACTORY_PROVIDER,
|
|
50
63
|
QueueMetricsService,
|
|
51
64
|
],
|
|
52
65
|
exports: [QueueMetricsService],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue-metrics.module.js","sourceRoot":"","sources":["../../src/metrics/queue-metrics.module.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAsB,MAAM,EAAiB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"queue-metrics.module.js","sourceRoot":"","sources":["../../src/metrics/queue-metrics.module.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAsB,MAAM,EAAE,MAAM,EAAiB,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAO5F,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAA4B,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAE3F,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,sBAAsB,GAAa;IACrC,OAAO,EAAE,2BAA2B;IACpC,UAAU,EACN,CAAC,OAA2B,EAAuB,EAAE,CACrD,CAAC,IAAI,EAAE,EAAE;QACL,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE;YAC1B,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,MAAM,EAAE,OAAO,CAAC,MAAM;SACzB,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CACtB,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,iCAAiC,CAAC,CACxE,CAAC;QACF,OAAO,KAAK,CAAC;IACjB,CAAC;IACL,MAAM,EAAE,CAAC,qBAAqB,CAAC;CAClC,CAAC;AAEF;;;;GAIG;AAEI,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAC3B,MAAM,CAAC,OAAO,CAAC,OAA4B;QACvC,OAAO;YACH,MAAM,EAAE,oBAAkB;YAC1B,WAAW,EAAE,CAAC,4BAA4B,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC/D,SAAS,EAAE;gBACP,EAAE,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,OAAO,EAAE;gBACrD,sBAAsB;gBACtB,mBAAmB;aACtB;YACD,OAAO,EAAE,CAAC,mBAAmB,CAAC;SACjC,CAAC;IACN,CAAC;IAED,iGAAiG;IACjG,MAAM,CAAC,YAAY,CAAC,OAAiC;QACjD,OAAO;YACH,MAAM,EAAE,oBAAkB;YAC1B,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;YAC9B,WAAW,EAAE,CAAC,4BAA4B,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC/D,SAAS,EAAE;gBACP;oBACI,OAAO,EAAE,qBAAqB;oBAC9B,UAAU,EAAE,OAAO,CAAC,UAAU;oBAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;iBAC/B;gBACD,sBAAsB;gBACtB,mBAAmB;aACtB;YACD,OAAO,EAAE,CAAC,mBAAmB,CAAC;SACjC,CAAC;IACN,CAAC;CACJ,CAAA;AAhCY,kBAAkB;IAD9B,MAAM,CAAC,EAAE,CAAC;GACE,kBAAkB,CAgC9B"}
|
|
@@ -3,15 +3,20 @@ import type { Queue } from 'bullmq';
|
|
|
3
3
|
import type { QueueMetricsConfig } from '../types/queue-metrics-options.type.js';
|
|
4
4
|
/** The calls `/metrics` makes on a queue. */
|
|
5
5
|
export type MetricsQueue = Pick<Queue, 'name' | 'getJobCounts' | 'getMetrics' | 'isPaused' | 'close'>;
|
|
6
|
+
/** Opens the queue of one name; called on the first scrape, never at boot. */
|
|
7
|
+
export type MetricsQueueFactory = (name: string) => MetricsQueue;
|
|
6
8
|
/**
|
|
7
9
|
* Reads the configured queues for `/metrics`. The counters live in Redis and
|
|
8
|
-
* are the same whichever pod reads them.
|
|
10
|
+
* are the same whichever pod reads them. The queues open on the first scrape:
|
|
11
|
+
* booting the role (or a test of its module) connects to nothing.
|
|
9
12
|
*/
|
|
10
13
|
export declare class QueueMetricsService implements OnModuleDestroy {
|
|
11
14
|
private readonly options;
|
|
12
|
-
private readonly
|
|
15
|
+
private readonly open;
|
|
13
16
|
private readonly logger;
|
|
14
|
-
|
|
17
|
+
private queues?;
|
|
18
|
+
constructor(options: QueueMetricsConfig, open: MetricsQueueFactory);
|
|
19
|
+
private getQueues;
|
|
15
20
|
/** Every queue in the Prometheus text format; a 503 when Redis does not answer in time. */
|
|
16
21
|
render(): Promise<string>;
|
|
17
22
|
onModuleDestroy(): Promise<void>;
|
|
@@ -12,7 +12,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
};
|
|
13
13
|
var QueueMetricsService_1;
|
|
14
14
|
import { Inject, Injectable, Logger, ServiceUnavailableException, } from '@nestjs/common';
|
|
15
|
-
import { DEFAULT_METRICS_TIMEOUT_MS, QUEUE_METRICS_OPTIONS,
|
|
15
|
+
import { DEFAULT_METRICS_TIMEOUT_MS, QUEUE_METRICS_OPTIONS, QUEUE_METRICS_QUEUE_FACTORY, } from '../bullmq.constants.js';
|
|
16
16
|
import { renderPrometheus } from './prometheus.util.js';
|
|
17
17
|
async function snapshotOf(queue) {
|
|
18
18
|
const [counts, completed, failed, isPaused] = await Promise.all([
|
|
@@ -31,15 +31,21 @@ async function snapshotOf(queue) {
|
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Reads the configured queues for `/metrics`. The counters live in Redis and
|
|
34
|
-
* are the same whichever pod reads them.
|
|
34
|
+
* are the same whichever pod reads them. The queues open on the first scrape:
|
|
35
|
+
* booting the role (or a test of its module) connects to nothing.
|
|
35
36
|
*/
|
|
36
37
|
let QueueMetricsService = QueueMetricsService_1 = class QueueMetricsService {
|
|
37
38
|
options;
|
|
38
|
-
|
|
39
|
+
open;
|
|
39
40
|
logger = new Logger(QueueMetricsService_1.name);
|
|
40
|
-
|
|
41
|
+
queues;
|
|
42
|
+
constructor(options, open) {
|
|
41
43
|
this.options = options;
|
|
42
|
-
this.
|
|
44
|
+
this.open = open;
|
|
45
|
+
}
|
|
46
|
+
getQueues() {
|
|
47
|
+
this.queues ??= this.options.queues.map((name) => this.open(name));
|
|
48
|
+
return this.queues;
|
|
43
49
|
}
|
|
44
50
|
/** Every queue in the Prometheus text format; a 503 when Redis does not answer in time. */
|
|
45
51
|
async render() {
|
|
@@ -50,7 +56,7 @@ let QueueMetricsService = QueueMetricsService_1 = class QueueMetricsService {
|
|
|
50
56
|
});
|
|
51
57
|
try {
|
|
52
58
|
const snapshots = await Promise.race([
|
|
53
|
-
Promise.all(this.
|
|
59
|
+
Promise.all(this.getQueues().map(snapshotOf)),
|
|
54
60
|
timeout,
|
|
55
61
|
]);
|
|
56
62
|
return renderPrometheus(snapshots);
|
|
@@ -64,14 +70,14 @@ let QueueMetricsService = QueueMetricsService_1 = class QueueMetricsService {
|
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
async onModuleDestroy() {
|
|
67
|
-
await Promise.all(this.queues.map((queue) => queue.close()));
|
|
73
|
+
await Promise.all((this.queues ?? []).map((queue) => queue.close()));
|
|
68
74
|
}
|
|
69
75
|
};
|
|
70
76
|
QueueMetricsService = QueueMetricsService_1 = __decorate([
|
|
71
77
|
Injectable(),
|
|
72
78
|
__param(0, Inject(QUEUE_METRICS_OPTIONS)),
|
|
73
|
-
__param(1, Inject(
|
|
74
|
-
__metadata("design:paramtypes", [Object,
|
|
79
|
+
__param(1, Inject(QUEUE_METRICS_QUEUE_FACTORY)),
|
|
80
|
+
__metadata("design:paramtypes", [Object, Function])
|
|
75
81
|
], QueueMetricsService);
|
|
76
82
|
export { QueueMetricsService };
|
|
77
83
|
//# sourceMappingURL=queue-metrics.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue-metrics.service.js","sourceRoot":"","sources":["../../src/metrics/queue-metrics.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EACH,MAAM,EACN,UAAU,EACV,MAAM,EAEN,2BAA2B,GAC9B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACH,0BAA0B,EAC1B,qBAAqB,EACrB,
|
|
1
|
+
{"version":3,"file":"queue-metrics.service.js","sourceRoot":"","sources":["../../src/metrics/queue-metrics.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EACH,MAAM,EACN,UAAU,EACV,MAAM,EAEN,2BAA2B,GAC9B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACH,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,GAC9B,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAWxD,KAAK,UAAU,UAAU,CAAC,KAAmB;IACzC,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC5D,KAAK,CAAC,YAAY,EAAE;QACpB,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC;QACnC,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;QAChC,KAAK,CAAC,QAAQ,EAAE;KACnB,CAAC,CAAC;IACH,OAAO;QACH,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM;QACN,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,KAAK;QAC/B,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK;QACzB,QAAQ;KACX,CAAC;AACN,CAAC;AAED;;;;GAIG;AAEI,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAKwB;IACM;IALzC,MAAM,GAAG,IAAI,MAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,CAAkB;IAEhC,YACoD,OAA2B,EACrB,IAAyB;QAD/B,YAAO,GAAP,OAAO,CAAoB;QAC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CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACzE,CAAC;CACJ,CAAA;AAzCY,mBAAmB;IAD/B,UAAU,EAAE;IAMJ,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;IAC7B,WAAA,MAAM,CAAC,2BAA2B,CAAC,CAAA;;GAN/B,mBAAmB,CAyC/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seta-labs/nestjs-bullmq",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "BullMQ queues for NestJS apps: default job and worker options, one log line per job outcome with a per-minute summary per queue, and the queue counters in the Prometheus format",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|