@seta-labs/nestjs-bullmq 0.1.0 → 0.2.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/README.md +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/metrics/queue-metrics.module.d.ts +3 -1
- package/dist/metrics/queue-metrics.module.js +23 -5
- package/dist/metrics/queue-metrics.module.js.map +1 -1
- package/dist/metrics/queue-metrics.service.d.ts +2 -2
- package/dist/metrics/queue-metrics.service.js.map +1 -1
- package/dist/types/queue-metrics-options.type.d.ts +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,6 +71,17 @@ QueueMetricsModule.forRoot({
|
|
|
71
71
|
}),
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
+
With the connection in the app's typed environment, build the options from it:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
QueueMetricsModule.forRootAsync({
|
|
78
|
+
imports: [ConfigModule],
|
|
79
|
+
inject: [ENV],
|
|
80
|
+
useFactory: (env: Env) => ({ connection: redisConnection(env), queues: QUEUE_NAMES }),
|
|
81
|
+
decorators: [Public()],
|
|
82
|
+
}),
|
|
83
|
+
```
|
|
84
|
+
|
|
74
85
|
| Series | Type | |
|
|
75
86
|
| ----------------------------------- | ------- | -------------------------------------------------------------------------------------------------------- |
|
|
76
87
|
| `bullmq_job_count{queue,state}` | gauge | jobs per state: `waiting`, `active`, `delayed`, `prioritized`, `waiting-children`, `completed`, `failed` |
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export { QueueMetricsService } from './metrics/queue-metrics.service.js';
|
|
|
5
5
|
export { queueDefaults, workerDefaults } from './queue-defaults.util.js';
|
|
6
6
|
export type { ObservedWorker } from './types/observed-worker.type.js';
|
|
7
7
|
export type { QueueEventsOptions } from './types/queue-events-options.type.js';
|
|
8
|
-
export type { QueueMetricsOptions } from './types/queue-metrics-options.type.js';
|
|
8
|
+
export type { QueueMetricsAsyncOptions, QueueMetricsConfig, QueueMetricsOptions, } from './types/queue-metrics-options.type.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
-
import type { QueueMetricsOptions } from '../types/queue-metrics-options.type.js';
|
|
2
|
+
import type { QueueMetricsAsyncOptions, QueueMetricsOptions } from '../types/queue-metrics-options.type.js';
|
|
3
3
|
/**
|
|
4
4
|
* `GET /metrics`: the configured queues in the Prometheus text format. Import
|
|
5
5
|
* it in a role whose port no ingress publishes (a headless role on its health
|
|
@@ -7,4 +7,6 @@ import type { QueueMetricsOptions } from '../types/queue-metrics-options.type.js
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class QueueMetricsModule {
|
|
9
9
|
static forRoot(options: QueueMetricsOptions): DynamicModule;
|
|
10
|
+
/** Same as `forRoot`, with the options built from injected providers (the app's environment). */
|
|
11
|
+
static forRootAsync(options: QueueMetricsAsyncOptions): DynamicModule;
|
|
10
12
|
}
|
|
@@ -10,6 +10,12 @@ import { Queue } from 'bullmq';
|
|
|
10
10
|
import { QUEUE_METRICS_OPTIONS, QUEUE_METRICS_QUEUES } from '../bullmq.constants.js';
|
|
11
11
|
import { createQueueMetricsController } from './queue-metrics.controller.js';
|
|
12
12
|
import { QueueMetricsService } from './queue-metrics.service.js';
|
|
13
|
+
/** One `Queue` per configured name, closed by `QueueMetricsService` on shutdown. */
|
|
14
|
+
const QUEUES_PROVIDER = {
|
|
15
|
+
provide: QUEUE_METRICS_QUEUES,
|
|
16
|
+
useFactory: (options) => options.queues.map((name) => new Queue(name, { connection: options.connection, prefix: options.prefix })),
|
|
17
|
+
inject: [QUEUE_METRICS_OPTIONS],
|
|
18
|
+
};
|
|
13
19
|
/**
|
|
14
20
|
* `GET /metrics`: the configured queues in the Prometheus text format. Import
|
|
15
21
|
* it in a role whose port no ingress publishes (a headless role on its health
|
|
@@ -22,13 +28,25 @@ let QueueMetricsModule = QueueMetricsModule_1 = class QueueMetricsModule {
|
|
|
22
28
|
controllers: [createQueueMetricsController(options.decorators)],
|
|
23
29
|
providers: [
|
|
24
30
|
{ provide: QUEUE_METRICS_OPTIONS, useValue: options },
|
|
31
|
+
QUEUES_PROVIDER,
|
|
32
|
+
QueueMetricsService,
|
|
33
|
+
],
|
|
34
|
+
exports: [QueueMetricsService],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Same as `forRoot`, with the options built from injected providers (the app's environment). */
|
|
38
|
+
static forRootAsync(options) {
|
|
39
|
+
return {
|
|
40
|
+
module: QueueMetricsModule_1,
|
|
41
|
+
imports: options.imports ?? [],
|
|
42
|
+
controllers: [createQueueMetricsController(options.decorators)],
|
|
43
|
+
providers: [
|
|
25
44
|
{
|
|
26
|
-
provide:
|
|
27
|
-
useFactory:
|
|
28
|
-
|
|
29
|
-
prefix: options.prefix,
|
|
30
|
-
})),
|
|
45
|
+
provide: QUEUE_METRICS_OPTIONS,
|
|
46
|
+
useFactory: options.useFactory,
|
|
47
|
+
inject: options.inject ?? [],
|
|
31
48
|
},
|
|
49
|
+
QUEUES_PROVIDER,
|
|
32
50
|
QueueMetricsService,
|
|
33
51
|
],
|
|
34
52
|
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,
|
|
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;AAC3E,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAOrF,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,mBA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,kBAAkB;IAD9B,MAAM,CAAC,EAAE,CAAC;GACE,kBAAkB,CAgC9B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type OnModuleDestroy } from '@nestjs/common';
|
|
2
2
|
import type { Queue } from 'bullmq';
|
|
3
|
-
import type {
|
|
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
6
|
/**
|
|
@@ -11,7 +11,7 @@ export declare class QueueMetricsService implements OnModuleDestroy {
|
|
|
11
11
|
private readonly options;
|
|
12
12
|
private readonly queues;
|
|
13
13
|
private readonly logger;
|
|
14
|
-
constructor(options:
|
|
14
|
+
constructor(options: QueueMetricsConfig, queues: MetricsQueue[]);
|
|
15
15
|
/** Every queue in the Prometheus text format; a 503 when Redis does not answer in time. */
|
|
16
16
|
render(): Promise<string>;
|
|
17
17
|
onModuleDestroy(): Promise<void>;
|
|
@@ -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,oBAAoB,GACvB,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAQxD,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,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gBAAS,CAAC;YACP,YAAY,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;IACL,CAAC;IAED,KAAK,CAAC,eAAe;QACjB,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjE,CAAC;CACJ,CAAA;AAnCY,mBAAmB;IAD/B,UAAU,EAAE;IAKJ,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;IAC7B,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;;GALxB,mBAAmB,CAmC/B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FactoryProvider, ModuleMetadata } from '@nestjs/common';
|
|
1
2
|
import type { ConnectionOptions } from 'bullmq';
|
|
2
3
|
export interface QueueMetricsOptions {
|
|
3
4
|
/** Redis of the queues; an ioredis instance is shared by every queue read. */
|
|
@@ -11,3 +12,13 @@ export interface QueueMetricsOptions {
|
|
|
11
12
|
/** Time allowed to read every queue before the scrape fails with a 503. Default `5_000`. */
|
|
12
13
|
timeoutMs?: number;
|
|
13
14
|
}
|
|
15
|
+
/** What `forRootAsync` resolves: everything but the decorators, which the route needs when the module is built. */
|
|
16
|
+
export type QueueMetricsConfig = Omit<QueueMetricsOptions, 'decorators'>;
|
|
17
|
+
export interface QueueMetricsAsyncOptions {
|
|
18
|
+
/** Modules that export what `inject` names, e.g. the app's config module. */
|
|
19
|
+
imports?: ModuleMetadata['imports'];
|
|
20
|
+
inject?: FactoryProvider['inject'];
|
|
21
|
+
/** Builds the options from the injected providers, e.g. the app's typed environment. */
|
|
22
|
+
useFactory: (...args: never[]) => QueueMetricsConfig | Promise<QueueMetricsConfig>;
|
|
23
|
+
decorators?: MethodDecorator[];
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seta-labs/nestjs-bullmq",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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": {
|