@zintrust/queue-monitor 2.4.2 → 2.4.4
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/QueueMonitoringService.d.ts +1 -0
- package/dist/QueueMonitoringService.js +34 -7
- package/dist/build-manifest.json +17 -17
- package/dist/driver.d.ts +14 -0
- package/dist/driver.js +87 -17
- package/dist/index.js +41 -12
- package/dist/runtime-index.js +27 -4
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ type QueueMonitoringConfig = {
|
|
|
22
22
|
intervalMs: number;
|
|
23
23
|
};
|
|
24
24
|
type QueueMonitoringCallback = (data: QueueSnapshotData) => void;
|
|
25
|
+
export declare const emptyLockAnalytics: () => LockAnalytics;
|
|
25
26
|
export declare function getRecentJobsForSelection(queueName: string, metrics: Metrics, driver: QueueDriver, queueNames?: ReadonlyArray<string>): Promise<JobSummary[]>;
|
|
26
27
|
export declare const QueueMonitoringService: Readonly<{
|
|
27
28
|
subscribe(callback: QueueMonitoringCallback, config: QueueMonitoringConfig): void;
|
|
@@ -6,6 +6,11 @@ const objectIds = new WeakMap();
|
|
|
6
6
|
let nextObjectId = 0;
|
|
7
7
|
const isAllQueuesSelection = (queue) => queue === ALL_QUEUES;
|
|
8
8
|
const sortJobsByTimestamp = (jobs) => jobs.toSorted((left, right) => right.timestamp - left.timestamp);
|
|
9
|
+
export const emptyLockAnalytics = () => ({
|
|
10
|
+
locks: [],
|
|
11
|
+
metrics: { active: 0, attempts: 0, acquired: 0, collisions: 0, collisionRate: 0 },
|
|
12
|
+
histogram: [],
|
|
13
|
+
});
|
|
9
14
|
const getObjectId = (value) => {
|
|
10
15
|
const existing = objectIds.get(value);
|
|
11
16
|
if (existing !== undefined)
|
|
@@ -36,12 +41,23 @@ export async function getRecentJobsForSelection(queueName, metrics, driver, queu
|
|
|
36
41
|
return getRecentJobsForQueue(queueName, metrics, driver);
|
|
37
42
|
}
|
|
38
43
|
const names = Array.from(new Set((queueNames ?? (await driver.getQueues())).filter(Boolean)));
|
|
39
|
-
const jobsByQueue = await Promise.all(names.map(async (name) =>
|
|
44
|
+
const jobsByQueue = await Promise.all(names.map(async (name) => {
|
|
45
|
+
try {
|
|
46
|
+
return await getRecentJobsForQueue(name, metrics, driver);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
Logger.warn('[queue-monitor] Recent jobs lookup failed; returning no jobs', error);
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
40
53
|
return sortJobsByTimestamp(jobsByQueue.flat()).slice(0, 100);
|
|
41
54
|
}
|
|
42
55
|
const buildSnapshotPayload = async (config) => {
|
|
43
56
|
const { getSnapshot, getLocks, metrics, driver, queue: configuredQueue, pattern } = config;
|
|
44
|
-
const snapshot = await getSnapshot()
|
|
57
|
+
const snapshot = await getSnapshot().catch((error) => {
|
|
58
|
+
Logger.warn('[queue-monitor] Snapshot unavailable; returning empty snapshot', error);
|
|
59
|
+
return { status: 'ok', startedAt: new Date().toISOString(), queues: [] };
|
|
60
|
+
});
|
|
45
61
|
let queue;
|
|
46
62
|
if (isAllQueuesSelection(configuredQueue)) {
|
|
47
63
|
queue = ALL_QUEUES;
|
|
@@ -59,9 +75,15 @@ const buildSnapshotPayload = async (config) => {
|
|
|
59
75
|
queue,
|
|
60
76
|
snapshot,
|
|
61
77
|
jobs: queue
|
|
62
|
-
? await getRecentJobsForSelection(queue, metrics, driver, snapshot.queues.map((candidate) => candidate.name))
|
|
78
|
+
? await getRecentJobsForSelection(queue, metrics, driver, snapshot.queues.map((candidate) => candidate.name)).catch((error) => {
|
|
79
|
+
Logger.warn('[queue-monitor] Recent jobs unavailable; returning no jobs', error);
|
|
80
|
+
return [];
|
|
81
|
+
})
|
|
63
82
|
: [],
|
|
64
|
-
locks: await getLocks(pattern)
|
|
83
|
+
locks: await getLocks(pattern).catch((error) => {
|
|
84
|
+
Logger.warn('[queue-monitor] Lock analytics unavailable; returning empty analytics', error);
|
|
85
|
+
return emptyLockAnalytics();
|
|
86
|
+
}),
|
|
65
87
|
};
|
|
66
88
|
};
|
|
67
89
|
const pushSnapshot = async (channel) => {
|
|
@@ -214,8 +236,10 @@ export const QueueMonitoringStream = (res, req, getSnapshot, getLocks, metrics,
|
|
|
214
236
|
});
|
|
215
237
|
};
|
|
216
238
|
export async function getRecentJobsForQueue(queueName, metrics, driver) {
|
|
217
|
-
const recent = await
|
|
218
|
-
|
|
239
|
+
const [recent, failed] = await Promise.all([
|
|
240
|
+
metrics.getRecentJobs(queueName).catch(() => []),
|
|
241
|
+
metrics.getFailedJobs(queueName).catch(() => []),
|
|
242
|
+
]);
|
|
219
243
|
const all = sortJobsByTimestamp([...recent, ...failed].map((job) => ({
|
|
220
244
|
...job,
|
|
221
245
|
queue: job.queue ?? queueName,
|
|
@@ -223,7 +247,10 @@ export async function getRecentJobsForQueue(queueName, metrics, driver) {
|
|
|
223
247
|
if (all.length > 0) {
|
|
224
248
|
return all;
|
|
225
249
|
}
|
|
226
|
-
const jobs = await driver.getRecentJobs(queueName, 100)
|
|
250
|
+
const jobs = await driver.getRecentJobs(queueName, 100).catch((error) => {
|
|
251
|
+
Logger.warn('[queue-monitor] Driver recent jobs unavailable; returning no jobs', error);
|
|
252
|
+
return [];
|
|
253
|
+
});
|
|
227
254
|
const now = Date.now();
|
|
228
255
|
return jobs.map((job) => {
|
|
229
256
|
// Use the actual state from BullMQ if available
|
package/dist/build-manifest.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/queue-monitor",
|
|
3
|
-
"version": "2.4.
|
|
4
|
-
"buildDate": "2026-
|
|
3
|
+
"version": "2.4.3",
|
|
4
|
+
"buildDate": "2026-06-01T13:35:49.849Z",
|
|
5
5
|
"buildEnvironment": {
|
|
6
6
|
"node": "v22.22.1",
|
|
7
7
|
"platform": "darwin",
|
|
8
8
|
"arch": "arm64"
|
|
9
9
|
},
|
|
10
10
|
"git": {
|
|
11
|
-
"commit": "
|
|
11
|
+
"commit": "98a0caf4",
|
|
12
12
|
"branch": "release"
|
|
13
13
|
},
|
|
14
14
|
"package": {
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"sha256": "33e57f6cec15b8dcb5886ca92644139d2e3ca1789aae1c3a4a066d75a273a6bb"
|
|
35
35
|
},
|
|
36
36
|
"QueueMonitoringService.d.ts": {
|
|
37
|
-
"size":
|
|
38
|
-
"sha256": "
|
|
37
|
+
"size": 1760,
|
|
38
|
+
"sha256": "949569e78120329804b63736b25c8cff9b5516ca44c9e7f1b2989d9cb09360b9"
|
|
39
39
|
},
|
|
40
40
|
"QueueMonitoringService.js": {
|
|
41
|
-
"size":
|
|
42
|
-
"sha256": "
|
|
41
|
+
"size": 10048,
|
|
42
|
+
"sha256": "3b7e85e6a0ba5dd958010bdf023052b1fb66cfbb52047554b326b4465b817719"
|
|
43
43
|
},
|
|
44
44
|
"build-manifest.json": {
|
|
45
|
-
"size":
|
|
46
|
-
"sha256": "
|
|
45
|
+
"size": 3869,
|
|
46
|
+
"sha256": "c1ba9522a69a44edce77119e8fd9df36dff9e8797d8a040448a8659da8b0721c"
|
|
47
47
|
},
|
|
48
48
|
"connection.d.ts": {
|
|
49
49
|
"size": 287,
|
|
@@ -78,20 +78,20 @@
|
|
|
78
78
|
"sha256": "fb91df973acd13a88cca443e50ecdd34944c66e1a1d48333f63099079a00f3c9"
|
|
79
79
|
},
|
|
80
80
|
"driver.d.ts": {
|
|
81
|
-
"size":
|
|
82
|
-
"sha256": "
|
|
81
|
+
"size": 1782,
|
|
82
|
+
"sha256": "a1629f48367efab3c0031ace21c5304821d01ca1d7027cc7a50b62570339c848"
|
|
83
83
|
},
|
|
84
84
|
"driver.js": {
|
|
85
|
-
"size":
|
|
86
|
-
"sha256": "
|
|
85
|
+
"size": 12473,
|
|
86
|
+
"sha256": "162ee0db3fe8a0cbc6378133a22d6df723a900e08ea74817c562b830a88338db"
|
|
87
87
|
},
|
|
88
88
|
"index.d.ts": {
|
|
89
89
|
"size": 2344,
|
|
90
90
|
"sha256": "370b578ca6412fbdbb2f6966c0899a4c9d6d1ab08defe48a9004564124b1f45e"
|
|
91
91
|
},
|
|
92
92
|
"index.js": {
|
|
93
|
-
"size":
|
|
94
|
-
"sha256": "
|
|
93
|
+
"size": 17226,
|
|
94
|
+
"sha256": "79f16f77f5e56c815212ffc43718fee07cf490c4f7fd9ff0e68fa656337b8a76"
|
|
95
95
|
},
|
|
96
96
|
"metrics-index.d.ts": {
|
|
97
97
|
"size": 239,
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
"sha256": "b4608f964f6c5cdb5469eb320683fee827734adcf1d03ea931766405451f35df"
|
|
115
115
|
},
|
|
116
116
|
"runtime-index.js": {
|
|
117
|
-
"size":
|
|
118
|
-
"sha256": "
|
|
117
|
+
"size": 9948,
|
|
118
|
+
"sha256": "7aa5c97aef19ec36e1309b9abc922481924672e4017bc3fe198b5eff7dabda86"
|
|
119
119
|
},
|
|
120
120
|
"worker.d.ts": {
|
|
121
121
|
"size": 338,
|
package/dist/driver.d.ts
CHANGED
|
@@ -2,6 +2,20 @@ import type { Job, JobsOptions } from 'bullmq';
|
|
|
2
2
|
import { type RedisConfig } from './connection.js';
|
|
3
3
|
export type JobPayload<T = unknown> = T;
|
|
4
4
|
export type JobCounts = Record<string, number>;
|
|
5
|
+
/**
|
|
6
|
+
* Standard BullMQ job-count buckets, all zero. Used when the backing store is
|
|
7
|
+
* unavailable so a queue is still listed (with empty counts) instead of being
|
|
8
|
+
* dropped from the snapshot entirely.
|
|
9
|
+
*/
|
|
10
|
+
export declare const emptyCounts: () => JobCounts;
|
|
11
|
+
/**
|
|
12
|
+
* Map a list of known queue names to entries with empty counts. Keeps the
|
|
13
|
+
* dashboard showing the configured queues during transient backend outages.
|
|
14
|
+
*/
|
|
15
|
+
export declare const emptyQueueStats: (queueNames: ReadonlyArray<string>) => Array<{
|
|
16
|
+
name: string;
|
|
17
|
+
counts: JobCounts;
|
|
18
|
+
}>;
|
|
5
19
|
export type RetrySnapshot = {
|
|
6
20
|
name?: string;
|
|
7
21
|
data: unknown;
|
package/dist/driver.js
CHANGED
|
@@ -4,7 +4,24 @@ 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
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Standard BullMQ job-count buckets, all zero. Used when the backing store is
|
|
9
|
+
* unavailable so a queue is still listed (with empty counts) instead of being
|
|
10
|
+
* dropped from the snapshot entirely.
|
|
11
|
+
*/
|
|
12
|
+
export const emptyCounts = () => ({
|
|
13
|
+
waiting: 0,
|
|
14
|
+
active: 0,
|
|
15
|
+
completed: 0,
|
|
16
|
+
failed: 0,
|
|
17
|
+
delayed: 0,
|
|
18
|
+
paused: 0,
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Map a list of known queue names to entries with empty counts. Keeps the
|
|
22
|
+
* dashboard showing the configured queues during transient backend outages.
|
|
23
|
+
*/
|
|
24
|
+
export const emptyQueueStats = (queueNames) => queueNames.map((name) => ({ name, counts: emptyCounts() }));
|
|
8
25
|
const shouldUseRedisRpcMonitorDriver = () => Env.USE_REDIS_PROXY === true && Env.get('REDIS_RPC_URL', '').trim() !== '';
|
|
9
26
|
const resolveRpcBaseUrl = () => {
|
|
10
27
|
const configured = Env.get('REDIS_RPC_URL', '').trim();
|
|
@@ -14,18 +31,41 @@ const resolveRpcBaseUrl = () => {
|
|
|
14
31
|
const port = Env.getInt('REDIS_RPC_PORT', 8794);
|
|
15
32
|
return `http://${host}:${port}`;
|
|
16
33
|
};
|
|
17
|
-
const
|
|
34
|
+
const createRequestId = () => {
|
|
35
|
+
const cryptoApi = globalThis.crypto;
|
|
36
|
+
if (typeof cryptoApi?.randomUUID === 'function')
|
|
37
|
+
return cryptoApi.randomUUID();
|
|
38
|
+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
39
|
+
};
|
|
40
|
+
const normalizeRpcBaseUrl = () => {
|
|
18
41
|
try {
|
|
19
|
-
|
|
20
|
-
return mod.createRedisRpcClient({
|
|
21
|
-
baseUrl: resolveRpcBaseUrl(),
|
|
22
|
-
secret: Env.get('REDIS_RPC_SECRET', Env.get('REDIS_PROXY_SECRET', Env.APP_KEY)),
|
|
23
|
-
});
|
|
42
|
+
return new URL(resolveRpcBaseUrl());
|
|
24
43
|
}
|
|
25
44
|
catch (error) {
|
|
26
|
-
throw ErrorFactory.createConfigError('
|
|
45
|
+
throw ErrorFactory.createConfigError('REDIS_RPC_URL must be a valid URL', error);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const callRedisRpc = async (service, method, payload = {}) => {
|
|
49
|
+
const endpoint = new URL('/rpc', normalizeRpcBaseUrl());
|
|
50
|
+
const secret = Env.get('REDIS_RPC_SECRET', Env.get('REDIS_PROXY_SECRET', Env.APP_KEY));
|
|
51
|
+
const response = await fetch(endpoint, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: {
|
|
54
|
+
'content-type': 'application/json',
|
|
55
|
+
...(secret.trim() === '' ? {} : { 'x-redis-rpc-secret': secret }),
|
|
56
|
+
},
|
|
57
|
+
body: JSON.stringify({ requestId: createRequestId(), service, method, payload }),
|
|
58
|
+
});
|
|
59
|
+
const body = (await response.json().catch(() => ({})));
|
|
60
|
+
if (!response.ok || body.ok !== true) {
|
|
61
|
+
throw ErrorFactory.createTryCatchError(body.error?.message ?? `Redis RPC request failed with status ${response.status}`);
|
|
27
62
|
}
|
|
63
|
+
return body.result;
|
|
28
64
|
};
|
|
65
|
+
const createRpcClient = async () => Object.freeze({
|
|
66
|
+
queue: (method, payload = {}) => callRedisRpc('queue', method, payload),
|
|
67
|
+
monitor: (method, payload = {}) => callRedisRpc('queue-monitor', method, payload),
|
|
68
|
+
});
|
|
29
69
|
const createRedisRpcDriver = () => {
|
|
30
70
|
const enqueue = async (name, payload, options) => {
|
|
31
71
|
const client = await createRpcClient();
|
|
@@ -42,22 +82,46 @@ const createRedisRpcDriver = () => {
|
|
|
42
82
|
enqueue,
|
|
43
83
|
async getJob(queueName, jobId) {
|
|
44
84
|
const client = await createRpcClient();
|
|
45
|
-
|
|
85
|
+
try {
|
|
86
|
+
return (await client.queue('getJob', { target: queueName, args: [jobId] }));
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
Logger.warn('[queue-monitor] Redis RPC job lookup failed; returning no job', error);
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
46
92
|
},
|
|
47
93
|
async getJobCounts(queueName) {
|
|
48
94
|
const client = await createRpcClient();
|
|
49
|
-
|
|
95
|
+
try {
|
|
96
|
+
return client.queue('getJobCounts', { target: queueName });
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
Logger.warn('[queue-monitor] Redis RPC job counts failed; returning empty counts', error);
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
50
102
|
},
|
|
51
103
|
async getJobCountsMany(queueNames) {
|
|
52
104
|
const client = await createRpcClient();
|
|
53
|
-
|
|
54
|
-
|
|
105
|
+
try {
|
|
106
|
+
const snapshot = await client.monitor('getSnapshot', { args: [queueNames] });
|
|
107
|
+
return snapshot.queues ?? emptyQueueStats(queueNames);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
Logger.warn('[queue-monitor] Redis RPC batch counts failed; returning known queues with empty counts', error);
|
|
111
|
+
return emptyQueueStats(queueNames);
|
|
112
|
+
}
|
|
55
113
|
},
|
|
56
114
|
async getRecentJobs(queueName, limit = 100) {
|
|
57
115
|
const client = await createRpcClient();
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
116
|
+
try {
|
|
117
|
+
return (await client.monitor('getRecentJobsForQueue', {
|
|
118
|
+
args: [queueName, limit],
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
Logger.warn('[queue-monitor] Redis RPC recent jobs failed; returning no jobs', error);
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
61
125
|
},
|
|
62
126
|
async retryJob(queueName, jobId) {
|
|
63
127
|
const client = await createRpcClient();
|
|
@@ -65,8 +129,14 @@ const createRedisRpcDriver = () => {
|
|
|
65
129
|
},
|
|
66
130
|
async getQueues() {
|
|
67
131
|
const client = await createRpcClient();
|
|
68
|
-
|
|
69
|
-
|
|
132
|
+
try {
|
|
133
|
+
const snapshot = await client.monitor('getSnapshot');
|
|
134
|
+
return (snapshot.queues ?? []).map((queue) => queue.name);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
Logger.warn('[queue-monitor] Redis RPC queue discovery failed; returning no queues', error);
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
70
140
|
},
|
|
71
141
|
async close() {
|
|
72
142
|
await Promise.resolve();
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,20 @@ import { createRedisConnection } from './connection.js';
|
|
|
8
8
|
import { getDashboardHtml } from './dashboard-ui.js';
|
|
9
9
|
import { createBullMQDriver as createQueueDriver, } from './driver.js';
|
|
10
10
|
import { createMetrics } from './metrics.js';
|
|
11
|
-
import { getRecentJobsForSelection, QueueMonitoringStream } from './QueueMonitoringService.js';
|
|
11
|
+
import { emptyLockAnalytics, getRecentJobsForSelection, QueueMonitoringStream, } from './QueueMonitoringService.js';
|
|
12
12
|
export { getRecentJobsForQueue, getRecentJobsForSelection, QueueMonitoringService, QueueMonitoringStream, } from './QueueMonitoringService.js';
|
|
13
13
|
export { createBullMQDriver } from './driver.js';
|
|
14
14
|
export { createMetrics } from './metrics.js';
|
|
15
15
|
export { createWorker as createQueueWorker } from './worker.js';
|
|
16
|
+
const emptyQueueCounts = () => ({
|
|
17
|
+
waiting: 0,
|
|
18
|
+
active: 0,
|
|
19
|
+
completed: 0,
|
|
20
|
+
failed: 0,
|
|
21
|
+
delayed: 0,
|
|
22
|
+
paused: 0,
|
|
23
|
+
});
|
|
24
|
+
const emptyQueueStats = (queues) => queues.map((name) => ({ name, counts: emptyQueueCounts() }));
|
|
16
25
|
const DEFAULTS = {
|
|
17
26
|
enabled: true,
|
|
18
27
|
basePath: '/queue-monitor',
|
|
@@ -156,6 +165,10 @@ function createGetLocks(redisConfig) {
|
|
|
156
165
|
histogram,
|
|
157
166
|
};
|
|
158
167
|
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
Logger.warn('[queue-monitor] Lock analytics failed; returning empty analytics', error);
|
|
170
|
+
return emptyLockAnalytics();
|
|
171
|
+
}
|
|
159
172
|
finally {
|
|
160
173
|
if (typeof client.quit === 'function') {
|
|
161
174
|
await client.quit();
|
|
@@ -227,9 +240,17 @@ function buildSettings(config) {
|
|
|
227
240
|
}
|
|
228
241
|
function createGetSnapshot(driver, startedAt, knownQueues) {
|
|
229
242
|
return async () => {
|
|
230
|
-
const persistedQueues = await resolveKnownQueues(knownQueues)
|
|
243
|
+
const persistedQueues = await resolveKnownQueues(knownQueues).catch((error) => {
|
|
244
|
+
Logger.warn('[queue-monitor] Known queue resolution failed; using no configured queues', error);
|
|
245
|
+
return [];
|
|
246
|
+
});
|
|
231
247
|
const shouldDiscoverQueues = persistedQueues.length === 0;
|
|
232
|
-
const discoveredQueues = shouldDiscoverQueues
|
|
248
|
+
const discoveredQueues = shouldDiscoverQueues
|
|
249
|
+
? await driver.getQueues().catch((error) => {
|
|
250
|
+
Logger.warn('[queue-monitor] Queue discovery failed; using no discovered queues', error);
|
|
251
|
+
return [];
|
|
252
|
+
})
|
|
253
|
+
: [];
|
|
233
254
|
const queues = Array.from(new Set([...persistedQueues, ...discoveredQueues])).sort((left, right) => left.localeCompare(right));
|
|
234
255
|
const QUEUE_MONITOR_LOGGING_ENABLED = Env.getBool('QUEUE_MONITOR_LOGGING_ENABLED', false);
|
|
235
256
|
if (QUEUE_MONITOR_LOGGING_ENABLED) {
|
|
@@ -243,15 +264,23 @@ function createGetSnapshot(driver, startedAt, knownQueues) {
|
|
|
243
264
|
});
|
|
244
265
|
}
|
|
245
266
|
const batchStartedAt = Date.now();
|
|
246
|
-
const stats =
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
267
|
+
const stats = await (async () => {
|
|
268
|
+
try {
|
|
269
|
+
return typeof driver.getJobCountsMany === 'function'
|
|
270
|
+
? (await driver.getJobCountsMany(queues)).map((item) => ({
|
|
271
|
+
name: item.name,
|
|
272
|
+
counts: item.counts,
|
|
273
|
+
}))
|
|
274
|
+
: await Promise.all(queues.map(async (name) => {
|
|
275
|
+
const counts = await driver.getJobCounts(name);
|
|
276
|
+
return { name, counts: counts };
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
Logger.warn('[queue-monitor] Queue count lookup failed; returning known queues with empty counts', error);
|
|
281
|
+
return emptyQueueStats(queues);
|
|
282
|
+
}
|
|
283
|
+
})();
|
|
255
284
|
if (QUEUE_MONITOR_LOGGING_ENABLED) {
|
|
256
285
|
Logger.info('[queue-monitor] snapshot queue counts resolved', {
|
|
257
286
|
durationMs: Date.now() - batchStartedAt,
|
package/dist/runtime-index.js
CHANGED
|
@@ -10,8 +10,18 @@ import { ShutdownTrace } from '@zintrust/core/workers';
|
|
|
10
10
|
import { createRedisConnection } from './connection.js';
|
|
11
11
|
import { createBullMQDriver } from './driver.js';
|
|
12
12
|
import { createMetrics } from './metrics.js';
|
|
13
|
+
import { emptyLockAnalytics } from './QueueMonitoringService.js';
|
|
13
14
|
export { createMetrics } from './metrics.js';
|
|
14
15
|
export { createWorker as createQueueWorker } from './worker.js';
|
|
16
|
+
const emptyQueueCounts = () => ({
|
|
17
|
+
waiting: 0,
|
|
18
|
+
active: 0,
|
|
19
|
+
completed: 0,
|
|
20
|
+
failed: 0,
|
|
21
|
+
delayed: 0,
|
|
22
|
+
paused: 0,
|
|
23
|
+
});
|
|
24
|
+
const emptyQueueStats = (queues) => queues.map((name) => ({ name, counts: emptyQueueCounts() }));
|
|
15
25
|
const DEFAULTS = {
|
|
16
26
|
enabled: true,
|
|
17
27
|
basePath: '/queue-monitor',
|
|
@@ -146,6 +156,10 @@ function createGetLocks(redisConfig) {
|
|
|
146
156
|
histogram,
|
|
147
157
|
};
|
|
148
158
|
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
Logger.warn('[queue-monitor] Lock analytics failed; returning empty analytics', error);
|
|
161
|
+
return emptyLockAnalytics();
|
|
162
|
+
}
|
|
149
163
|
finally {
|
|
150
164
|
if (typeof client.quit === 'function') {
|
|
151
165
|
await client.quit();
|
|
@@ -170,14 +184,23 @@ function buildSettings(config) {
|
|
|
170
184
|
function createGetSnapshot(driver, startedAt, knownQueues) {
|
|
171
185
|
return async () => {
|
|
172
186
|
const [discoveredQueues, persistedQueues] = await Promise.all([
|
|
173
|
-
driver.getQueues()
|
|
174
|
-
|
|
187
|
+
driver.getQueues().catch((error) => {
|
|
188
|
+
Logger.warn('[queue-monitor] Queue discovery failed; using no discovered queues', error);
|
|
189
|
+
return [];
|
|
190
|
+
}),
|
|
191
|
+
resolveKnownQueues(knownQueues).catch((error) => {
|
|
192
|
+
Logger.warn('[queue-monitor] Known queue resolution failed; using no configured queues', error);
|
|
193
|
+
return [];
|
|
194
|
+
}),
|
|
175
195
|
]);
|
|
176
196
|
const queues = Array.from(new Set([...persistedQueues, ...discoveredQueues])).sort((left, right) => left.localeCompare(right));
|
|
177
197
|
const stats = await Promise.all(queues.map(async (name) => {
|
|
178
|
-
const counts = await driver.getJobCounts(name);
|
|
198
|
+
const counts = await driver.getJobCounts(name).catch(() => ({}));
|
|
179
199
|
return { name, counts: counts };
|
|
180
|
-
}))
|
|
200
|
+
})).catch((error) => {
|
|
201
|
+
Logger.warn('[queue-monitor] Queue count lookup failed; returning known queues with empty counts', error);
|
|
202
|
+
return emptyQueueStats(queues);
|
|
203
|
+
});
|
|
181
204
|
return {
|
|
182
205
|
status: 'ok',
|
|
183
206
|
startedAt,
|