@zintrust/queue-monitor 2.4.0 → 2.4.2

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.
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@zintrust/queue-monitor",
3
- "version": "2.4.0",
4
- "buildDate": "2026-05-30T23:30:02.940Z",
3
+ "version": "2.4.1",
4
+ "buildDate": "2026-05-31T11:37:21.551Z",
5
5
  "buildEnvironment": {
6
- "node": "v20.20.2",
7
- "platform": "linux",
8
- "arch": "x64"
6
+ "node": "v22.22.1",
7
+ "platform": "darwin",
8
+ "arch": "arm64"
9
9
  },
10
10
  "git": {
11
- "commit": "8357ba1a",
12
- "branch": "master"
11
+ "commit": "e97b7b3d",
12
+ "branch": "release"
13
13
  },
14
14
  "package": {
15
15
  "engines": {
@@ -20,7 +20,8 @@
20
20
  "ioredis"
21
21
  ],
22
22
  "peerDependencies": [
23
- "@zintrust/core"
23
+ "@zintrust/core",
24
+ "@zintrust/redis-rpc"
24
25
  ]
25
26
  },
26
27
  "files": {
@@ -40,6 +41,10 @@
40
41
  "size": 8935,
41
42
  "sha256": "c099e8922dd5642bce33a7db4b4a98641cab16e45a4ab76f989ef76a1178700e"
42
43
  },
44
+ "build-manifest.json": {
45
+ "size": 3730,
46
+ "sha256": "f8860c23ea4936ad934d716cd6c818a959056530306a18d2dbe017cd25ef8044"
47
+ },
43
48
  "connection.d.ts": {
44
49
  "size": 287,
45
50
  "sha256": "dcc6ea45e59b0a2e8844b27f466dff4849618c06b74aae62a99c8edd772d0db0"
@@ -77,16 +82,16 @@
77
82
  "sha256": "91f705031e1abd9049e93c49a2cdd00552f41c4693f2f79fb3fbeeb6c67ac85a"
78
83
  },
79
84
  "driver.js": {
80
- "size": 6911,
81
- "sha256": "b29cabaf0010b2aad358af2adab337c28e056e60cdd8b5b7bdd9e95781bc6f56"
85
+ "size": 9763,
86
+ "sha256": "3f12f43c1b67091588dfcbbed70d39d046f88e4699db4c1cf4ee6f442b5b87dd"
82
87
  },
83
88
  "index.d.ts": {
84
89
  "size": 2344,
85
90
  "sha256": "370b578ca6412fbdbb2f6966c0899a4c9d6d1ab08defe48a9004564124b1f45e"
86
91
  },
87
92
  "index.js": {
88
- "size": 15814,
89
- "sha256": "bf6f0923142de3047c7317d0e7cd8395b44c21ddebb921fd044b73318c775e9b"
93
+ "size": 16079,
94
+ "sha256": "4e6d97afc428b9f3438be08711c79ea66711038a8d93c28e7074754a8b35ba4d"
90
95
  },
91
96
  "metrics-index.d.ts": {
92
97
  "size": 239,
package/dist/driver.js CHANGED
@@ -4,6 +4,75 @@ import { Logger } from '@zintrust/core/logger';
4
4
  import { getBullMQSafeQueueName } from '@zintrust/core/redis';
5
5
  import { Queue } from 'bullmq';
6
6
  import { createRedisConnection } from './connection.js';
7
+ const REDIS_RPC_PACKAGE = '@zintrust/redis-rpc';
8
+ const shouldUseRedisRpcMonitorDriver = () => Env.USE_REDIS_PROXY === true && Env.get('REDIS_RPC_URL', '').trim() !== '';
9
+ const resolveRpcBaseUrl = () => {
10
+ const configured = Env.get('REDIS_RPC_URL', '').trim();
11
+ if (configured.length > 0)
12
+ return configured;
13
+ const host = Env.get('REDIS_RPC_HOST', '127.0.0.1').trim() || '127.0.0.1';
14
+ const port = Env.getInt('REDIS_RPC_PORT', 8794);
15
+ return `http://${host}:${port}`;
16
+ };
17
+ const createRpcClient = async () => {
18
+ try {
19
+ const mod = (await import(REDIS_RPC_PACKAGE));
20
+ return mod.createRedisRpcClient({
21
+ baseUrl: resolveRpcBaseUrl(),
22
+ secret: Env.get('REDIS_RPC_SECRET', Env.get('REDIS_PROXY_SECRET', Env.APP_KEY)),
23
+ });
24
+ }
25
+ catch (error) {
26
+ throw ErrorFactory.createConfigError('@zintrust/redis-rpc is required when USE_REDIS_PROXY=true and REDIS_RPC_URL is configured', error);
27
+ }
28
+ };
29
+ const createRedisRpcDriver = () => {
30
+ const enqueue = async (name, payload, options) => {
31
+ const client = await createRpcClient();
32
+ const result = await client.queue('add', {
33
+ target: name,
34
+ args: ['default', payload, options ?? {}],
35
+ });
36
+ if (result.id === undefined || result.id === null) {
37
+ throw ErrorFactory.createTryCatchError(`Queue job id missing for ${name}`);
38
+ }
39
+ return String(result.id);
40
+ };
41
+ return Object.freeze({
42
+ enqueue,
43
+ async getJob(queueName, jobId) {
44
+ const client = await createRpcClient();
45
+ return (await client.queue('getJob', { target: queueName, args: [jobId] }));
46
+ },
47
+ async getJobCounts(queueName) {
48
+ const client = await createRpcClient();
49
+ return client.queue('getJobCounts', { target: queueName });
50
+ },
51
+ async getJobCountsMany(queueNames) {
52
+ const client = await createRpcClient();
53
+ const snapshot = await client.monitor('getSnapshot', { args: [queueNames] });
54
+ return snapshot.queues ?? [];
55
+ },
56
+ async getRecentJobs(queueName, limit = 100) {
57
+ const client = await createRpcClient();
58
+ return (await client.monitor('getRecentJobsForQueue', {
59
+ args: [queueName, limit],
60
+ }));
61
+ },
62
+ async retryJob(queueName, jobId) {
63
+ const client = await createRpcClient();
64
+ return client.queue('retryJob', { target: queueName, args: [jobId] });
65
+ },
66
+ async getQueues() {
67
+ const client = await createRpcClient();
68
+ const snapshot = await client.monitor('getSnapshot');
69
+ return (snapshot.queues ?? []).map((queue) => queue.name);
70
+ },
71
+ async close() {
72
+ await Promise.resolve();
73
+ },
74
+ });
75
+ };
7
76
  async function enrichJobsWithState(jobs) {
8
77
  await Promise.all(jobs.map(async (job) => {
9
78
  try {
@@ -46,23 +115,12 @@ async function discoverQueuesFromRedis(redis, inMemoryQueues) {
46
115
  }
47
116
  // eslint-disable-next-line max-lines-per-function
48
117
  export const createBullMQDriver = (config) => {
118
+ if (shouldUseRedisRpcMonitorDriver())
119
+ return createRedisRpcDriver();
49
120
  const queues = new Map();
50
- const requireDirectForScripts = Env.getBool('REDIS_REQUIRE_DIRECT_FOR_SCRIPTS', true) && Env.getBool('USE_REDIS_PROXY', false);
51
- let redis;
52
- // TODO remove when proxy convert to rpc
53
- if (requireDirectForScripts) {
54
- redis = {
55
- host: config.host,
56
- port: config.port,
57
- db: config.db,
58
- password: config.password,
59
- };
60
- }
61
- else {
62
- redis = createRedisConnection(config, 3, {
63
- subsystem: 'queue-monitor',
64
- });
65
- }
121
+ const redis = createRedisConnection(config, 3, {
122
+ subsystem: 'queue-monitor',
123
+ });
66
124
  const getQueue = (name) => {
67
125
  if (!queues.has(name)) {
68
126
  const prefix = getBullMQSafeQueueName();
@@ -97,30 +155,37 @@ export const createBullMQDriver = (config) => {
97
155
  };
98
156
  const getJobCountsMany = async (queueNames) => {
99
157
  const uniqueQueueNames = Array.from(new Set(queueNames.filter((queueName) => typeof queueName === 'string' && queueName.trim().length > 0)));
100
- Logger.info('[queue-monitor] getJobCountsMany start', {
101
- requestedCount: queueNames.length,
102
- uniqueCount: uniqueQueueNames.length,
103
- });
104
- const startedAt = Date.now();
105
- if (uniqueQueueNames.length === 0) {
106
- Logger.info('[queue-monitor] getJobCountsMany complete', {
107
- durationMs: Date.now() - startedAt,
158
+ const QUEUE_MONITOR_LOGGING_ENABLED = Env.getBool('QUEUE_MONITOR_LOGGING_ENABLED', false);
159
+ if (QUEUE_MONITOR_LOGGING_ENABLED) {
160
+ Logger.info('[queue-monitor] getJobCountsMany start', {
108
161
  requestedCount: queueNames.length,
109
162
  uniqueCount: uniqueQueueNames.length,
110
- pipelineCount: 0,
111
163
  });
164
+ }
165
+ const startedAt = Date.now();
166
+ if (uniqueQueueNames.length === 0) {
167
+ if (QUEUE_MONITOR_LOGGING_ENABLED) {
168
+ Logger.info('[queue-monitor] getJobCountsMany complete', {
169
+ durationMs: Date.now() - startedAt,
170
+ requestedCount: queueNames.length,
171
+ uniqueCount: uniqueQueueNames.length,
172
+ pipelineCount: 0,
173
+ });
174
+ }
112
175
  return [];
113
176
  }
114
177
  const stats = await Promise.all(uniqueQueueNames.map(async (name) => {
115
178
  const counts = await getJobCounts(name);
116
179
  return { name, counts };
117
180
  }));
118
- Logger.info('[queue-monitor] getJobCountsMany complete', {
119
- durationMs: Date.now() - startedAt,
120
- requestedCount: queueNames.length,
121
- uniqueCount: uniqueQueueNames.length,
122
- pipelineCount: uniqueQueueNames.length,
123
- });
181
+ if (QUEUE_MONITOR_LOGGING_ENABLED) {
182
+ Logger.info('[queue-monitor] getJobCountsMany complete', {
183
+ durationMs: Date.now() - startedAt,
184
+ requestedCount: queueNames.length,
185
+ uniqueCount: uniqueQueueNames.length,
186
+ pipelineCount: uniqueQueueNames.length,
187
+ });
188
+ }
124
189
  return stats;
125
190
  };
126
191
  const requeueFromSnapshot = async (queue, snapshot) => {
package/dist/index.js CHANGED
@@ -231,14 +231,17 @@ function createGetSnapshot(driver, startedAt, knownQueues) {
231
231
  const shouldDiscoverQueues = persistedQueues.length === 0;
232
232
  const discoveredQueues = shouldDiscoverQueues ? await driver.getQueues() : [];
233
233
  const queues = Array.from(new Set([...persistedQueues, ...discoveredQueues])).sort((left, right) => left.localeCompare(right));
234
- Logger.info('[queue-monitor] snapshot queue list resolved', {
235
- discoveredCount: discoveredQueues.length,
236
- persistedCount: persistedQueues.length,
237
- totalQueues: queues.length,
238
- usedRedisDiscovery: shouldDiscoverQueues,
239
- skippedRedisDiscovery: !shouldDiscoverQueues,
240
- hasBatchCounts: typeof driver.getJobCountsMany === 'function',
241
- });
234
+ const QUEUE_MONITOR_LOGGING_ENABLED = Env.getBool('QUEUE_MONITOR_LOGGING_ENABLED', false);
235
+ if (QUEUE_MONITOR_LOGGING_ENABLED) {
236
+ Logger.info('[queue-monitor] snapshot queue list resolved', {
237
+ discoveredCount: discoveredQueues.length,
238
+ persistedCount: persistedQueues.length,
239
+ totalQueues: queues.length,
240
+ usedRedisDiscovery: shouldDiscoverQueues,
241
+ skippedRedisDiscovery: !shouldDiscoverQueues,
242
+ hasBatchCounts: typeof driver.getJobCountsMany === 'function',
243
+ });
244
+ }
242
245
  const batchStartedAt = Date.now();
243
246
  const stats = typeof driver.getJobCountsMany === 'function'
244
247
  ? (await driver.getJobCountsMany(queues)).map((item) => ({
@@ -249,12 +252,14 @@ function createGetSnapshot(driver, startedAt, knownQueues) {
249
252
  const counts = await driver.getJobCounts(name);
250
253
  return { name, counts: counts };
251
254
  }));
252
- Logger.info('[queue-monitor] snapshot queue counts resolved', {
253
- durationMs: Date.now() - batchStartedAt,
254
- totalQueues: queues.length,
255
- returnedQueues: stats.length,
256
- usedBatchCounts: typeof driver.getJobCountsMany === 'function',
257
- });
255
+ if (QUEUE_MONITOR_LOGGING_ENABLED) {
256
+ Logger.info('[queue-monitor] snapshot queue counts resolved', {
257
+ durationMs: Date.now() - batchStartedAt,
258
+ totalQueues: queues.length,
259
+ returnedQueues: stats.length,
260
+ usedBatchCounts: typeof driver.getJobCountsMany === 'function',
261
+ });
262
+ }
258
263
  return {
259
264
  status: 'ok',
260
265
  startedAt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/queue-monitor",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "Queue monitoring package for ZinTrust with BullMQ and Redis.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -36,7 +36,13 @@
36
36
  "node": ">=20.0.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "@zintrust/core": "*"
39
+ "@zintrust/core": "*",
40
+ "@zintrust/redis-rpc": "*"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "@zintrust/redis-rpc": {
44
+ "optional": true
45
+ }
40
46
  },
41
47
  "publishConfig": {
42
48
  "access": "public"
@@ -56,4 +62,4 @@
56
62
  "bullmq": "^5.77.6",
57
63
  "ioredis": "^5.11.0"
58
64
  }
59
- }
65
+ }