@leoribeiroweb/nest-queue 0.2.0 → 1.0.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 CHANGED
@@ -216,21 +216,23 @@ throwing, so terminus returns a 503 naming the failing check instead of a 500
216
216
  with a stack. It joins **readiness**, not liveness: an unreachable queue should
217
217
  take the pod out of rotation, not restart a process that is still serving HTTP.
218
218
 
219
+ Pass the BullMQ `Queue` as it is, on either major: the indicator takes the
220
+ client from `queue.getBackend().client` when the queue has one (bullmq 6) and
221
+ from `queue.client` otherwise (bullmq 5).
222
+
219
223
  A `null` queue reports up, tagged `disabled`. Running without Redis is a
220
224
  supported deployment shape; the check that catches a production deployment
221
225
  which *lost* `REDIS_HOST` belongs on the configuration, not on this probe.
222
226
 
223
227
  ## Requirements
224
228
 
225
- Node `>=20.11.0`. Peer dependencies: `@leoribeiroweb/nest-core`,
226
- `@leoribeiroweb/nest-redis` ^0.1, `@nestjs/common` ^11, `@nestjs/terminus` ^11,
229
+ Node `>=22.12.0`. Peer dependencies: `@leoribeiroweb/nest-core` ^1.0.0,
230
+ `@leoribeiroweb/nest-redis` ^1.0.0, `@nestjs/common` ^11, `@nestjs/terminus` ^11,
227
231
  `bullmq` `^5 || ^6`, `reflect-metadata` ^0.2.
228
232
 
229
- The accepted `@leoribeiroweb/nest-core` range is the one in the `peerDependencies`
230
- of this package's `package.json` (`npm view @leoribeiroweb/nest-queue@<version>
231
- peerDependencies` for a published version). It has moved with every core minor,
232
- so read it there rather than from this page, and bump `nest-core` and
233
- `nest-queue` in the same change.
233
+ Before 1.0.0 the core range moved with every core minor; from 1.0.0 a caret
234
+ crosses minors, so any 1.x core and redis satisfy it. Bump the
235
+ `@leoribeiroweb/*` packages to the same major in one change.
234
236
 
235
237
  Both BullMQ majors are exercised in CI: the lockfile installs 6, which the live
236
238
  services run, and a separate job installs the floor of the range and re-runs
@@ -1,15 +1,32 @@
1
1
  import { type HealthCheckKind, type HealthIndicatorRegistration } from '@leoribeiroweb/nest-core';
2
+ /**
3
+ * The Redis client a probe pings. A bullmq 5 client is an ioredis `Redis` or
4
+ * `Cluster`, which has `ping()`. A bullmq 6 client is its own `IRedisClient`,
5
+ * which declares no `ping` but forwards any command through `runCommand`.
6
+ */
7
+ export type HealthProbeClient = {
8
+ ping(): Promise<unknown>;
9
+ } | {
10
+ runCommand(name: string, args: any[]): Promise<unknown>;
11
+ };
2
12
  /**
3
13
  * The part of a BullMQ `Queue` a probe touches. Structural, so the indicator
4
14
  * can be exercised without a live Redis — which is the only way "reports
5
15
  * unhealthy when Redis is unreachable" is a tested claim rather than an
6
16
  * inspected one.
17
+ *
18
+ * A real `Queue` of either supported major satisfies it: bullmq 5 exposes the
19
+ * client as `queue.client`, bullmq 6 as `queue.getBackend().client` (#102).
20
+ * Both are optional here because each major has only one of them; a queue with
21
+ * neither reports `down`.
7
22
  */
8
23
  export interface HealthProbeQueue {
9
- /** BullMQ resolves its client lazily; the promise rejects when it cannot connect. */
10
- readonly client: Promise<{
11
- ping(): Promise<unknown>;
12
- }>;
24
+ /** bullmq 5. Resolved lazily; the promise rejects when it cannot connect. */
25
+ readonly client?: Promise<HealthProbeClient>;
26
+ /** bullmq 6. The backend owns the connection; same lazy client promise. */
27
+ getBackend?(): {
28
+ readonly client: Promise<HealthProbeClient>;
29
+ };
13
30
  getWaitingCount(): Promise<number>;
14
31
  getActiveCount(): Promise<number>;
15
32
  getFailedCount(): Promise<number>;
@@ -2,6 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createQueueHealthIndicator = createQueueHealthIndicator;
4
4
  const nest_core_1 = require("@leoribeiroweb/nest-core");
5
+ /**
6
+ * Finds the client by what the queue offers rather than by the installed
7
+ * bullmq version: the backend's client first (bullmq 6), then the queue's own
8
+ * getter (bullmq 5).
9
+ */
10
+ function probeClient(queue) {
11
+ if (typeof queue.getBackend === 'function') {
12
+ return queue.getBackend().client;
13
+ }
14
+ if (queue.client !== undefined) {
15
+ return queue.client;
16
+ }
17
+ return Promise.reject(new Error('the queue exposes no Redis client (neither getBackend().client nor client)'));
18
+ }
19
+ async function ping(client) {
20
+ if ('runCommand' in client && typeof client.runCommand === 'function') {
21
+ await client.runCommand('ping', []);
22
+ return;
23
+ }
24
+ await client.ping();
25
+ }
5
26
  /**
6
27
  * A readiness check for one BullMQ queue.
7
28
  *
@@ -31,8 +52,7 @@ function createQueueHealthIndicator({ name, queue, kinds = ['readiness'], }) {
31
52
  return { [name]: { status: 'up', queue: 'disabled' } };
32
53
  }
33
54
  try {
34
- const client = await queue.client;
35
- await client.ping();
55
+ await ping(await probeClient(queue));
36
56
  const [waiting, active, failed] = await Promise.all([
37
57
  queue.getWaitingCount(),
38
58
  queue.getActiveCount(),
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { createBullConnection } from './connection/bull-connection';
2
- export { createQueueHealthIndicator, type HealthProbeQueue, type QueueHealthIndicatorOptions, } from './health/queue-health';
2
+ export { createQueueHealthIndicator, type HealthProbeClient, type HealthProbeQueue, type QueueHealthIndicatorOptions, } from './health/queue-health';
3
3
  export { BullQueueHost, bullQueueFactory, type BullQueueHostOptions, type BullQueueOptions, type HostedQueue, type QueueFactory, type QueueHostLogger, } from './queue/bull-queue-host';
4
4
  export { deterministicJobId } from './queue/job-id';
5
5
  export { isLiveJobState } from './queue/live-job-state';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leoribeiroweb/nest-queue",
3
- "version": "0.2.0",
3
+ "version": "1.0.0",
4
4
  "description": "Shared BullMQ building blocks: the dual-mode Redis connection as BullMQ options, base queue and worker hosts, and a queue health indicator.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "dist"
26
26
  ],
27
27
  "engines": {
28
- "node": ">=20.11.0"
28
+ "node": ">=22.12.0"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
@@ -35,8 +35,8 @@
35
35
  "prepublishOnly": "npm run build"
36
36
  },
37
37
  "peerDependencies": {
38
- "@leoribeiroweb/nest-core": ">=0.8.0 <1.0.0",
39
- "@leoribeiroweb/nest-redis": ">=0.1.0 <1.0.0",
38
+ "@leoribeiroweb/nest-core": "^1.0.0",
39
+ "@leoribeiroweb/nest-redis": "^1.0.0",
40
40
  "@nestjs/common": "^11",
41
41
  "@nestjs/terminus": "^11",
42
42
  "bullmq": "^5 || ^6",