@zintrust/queue-monitor 2.1.4 → 2.1.6
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/driver.d.ts +4 -0
- package/dist/driver.js +30 -0
- package/dist/index.js +27 -8
- package/package.json +3 -3
package/dist/driver.d.ts
CHANGED
|
@@ -26,6 +26,10 @@ export type QueueDriver = {
|
|
|
26
26
|
enqueue<T>(name: string, payload: T, options?: JobsOptions): Promise<string>;
|
|
27
27
|
getJob(queueName: string, jobId: string): Promise<Job | undefined>;
|
|
28
28
|
getJobCounts(queueName: string): Promise<JobCounts>;
|
|
29
|
+
getJobCountsMany(queueNames: string[]): Promise<Array<{
|
|
30
|
+
name: string;
|
|
31
|
+
counts: Record<string, number>;
|
|
32
|
+
}>>;
|
|
29
33
|
getRecentJobs(queueName: string, limit?: number): Promise<Job[]>;
|
|
30
34
|
retryJob(queueName: string, jobId: string, snapshot?: RetrySnapshot): Promise<RetryJobResult>;
|
|
31
35
|
getQueues(): Promise<string[]>;
|
package/dist/driver.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ErrorFactory } from '@zintrust/core/errors';
|
|
2
|
+
import { Logger } from '@zintrust/core/logger';
|
|
2
3
|
import { getBullMQSafeQueueName } from '@zintrust/core/redis';
|
|
3
4
|
import { Queue } from 'bullmq';
|
|
4
5
|
import { createRedisConnection } from './connection';
|
|
@@ -79,6 +80,34 @@ export const createBullMQDriver = (config) => {
|
|
|
79
80
|
const queue = getQueue(queueName);
|
|
80
81
|
return queue.getJobCounts();
|
|
81
82
|
};
|
|
83
|
+
const getJobCountsMany = async (queueNames) => {
|
|
84
|
+
const uniqueQueueNames = Array.from(new Set(queueNames.filter((queueName) => typeof queueName === 'string' && queueName.trim().length > 0)));
|
|
85
|
+
Logger.info('[queue-monitor] getJobCountsMany start', {
|
|
86
|
+
requestedCount: queueNames.length,
|
|
87
|
+
uniqueCount: uniqueQueueNames.length,
|
|
88
|
+
});
|
|
89
|
+
const startedAt = Date.now();
|
|
90
|
+
if (uniqueQueueNames.length === 0) {
|
|
91
|
+
Logger.info('[queue-monitor] getJobCountsMany complete', {
|
|
92
|
+
durationMs: Date.now() - startedAt,
|
|
93
|
+
requestedCount: queueNames.length,
|
|
94
|
+
uniqueCount: uniqueQueueNames.length,
|
|
95
|
+
pipelineCount: 0,
|
|
96
|
+
});
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
const stats = await Promise.all(uniqueQueueNames.map(async (name) => {
|
|
100
|
+
const counts = await getJobCounts(name);
|
|
101
|
+
return { name, counts };
|
|
102
|
+
}));
|
|
103
|
+
Logger.info('[queue-monitor] getJobCountsMany complete', {
|
|
104
|
+
durationMs: Date.now() - startedAt,
|
|
105
|
+
requestedCount: queueNames.length,
|
|
106
|
+
uniqueCount: uniqueQueueNames.length,
|
|
107
|
+
pipelineCount: uniqueQueueNames.length,
|
|
108
|
+
});
|
|
109
|
+
return stats;
|
|
110
|
+
};
|
|
82
111
|
const requeueFromSnapshot = async (queue, snapshot) => {
|
|
83
112
|
try {
|
|
84
113
|
const requeued = await queue.add(snapshot.name ?? 'default', snapshot.data, snapshot.opts);
|
|
@@ -134,6 +163,7 @@ export const createBullMQDriver = (config) => {
|
|
|
134
163
|
enqueue,
|
|
135
164
|
getJob,
|
|
136
165
|
getJobCounts,
|
|
166
|
+
getJobCountsMany,
|
|
137
167
|
getRecentJobs,
|
|
138
168
|
retryJob,
|
|
139
169
|
getQueues,
|
package/dist/index.js
CHANGED
|
@@ -225,15 +225,34 @@ function buildSettings(config) {
|
|
|
225
225
|
}
|
|
226
226
|
function createGetSnapshot(driver, startedAt, knownQueues) {
|
|
227
227
|
return async () => {
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
]);
|
|
228
|
+
const persistedQueues = await resolveKnownQueues(knownQueues);
|
|
229
|
+
const shouldDiscoverQueues = persistedQueues.length === 0;
|
|
230
|
+
const discoveredQueues = shouldDiscoverQueues ? await driver.getQueues() : [];
|
|
232
231
|
const queues = Array.from(new Set([...persistedQueues, ...discoveredQueues])).sort((left, right) => left.localeCompare(right));
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
232
|
+
Logger.info('[queue-monitor] snapshot queue list resolved', {
|
|
233
|
+
discoveredCount: discoveredQueues.length,
|
|
234
|
+
persistedCount: persistedQueues.length,
|
|
235
|
+
totalQueues: queues.length,
|
|
236
|
+
usedRedisDiscovery: shouldDiscoverQueues,
|
|
237
|
+
skippedRedisDiscovery: !shouldDiscoverQueues,
|
|
238
|
+
hasBatchCounts: typeof driver.getJobCountsMany === 'function',
|
|
239
|
+
});
|
|
240
|
+
const batchStartedAt = Date.now();
|
|
241
|
+
const stats = typeof driver.getJobCountsMany === 'function'
|
|
242
|
+
? (await driver.getJobCountsMany(queues)).map((item) => ({
|
|
243
|
+
name: item.name,
|
|
244
|
+
counts: item.counts,
|
|
245
|
+
}))
|
|
246
|
+
: await Promise.all(queues.map(async (name) => {
|
|
247
|
+
const counts = await driver.getJobCounts(name);
|
|
248
|
+
return { name, counts: counts };
|
|
249
|
+
}));
|
|
250
|
+
Logger.info('[queue-monitor] snapshot queue counts resolved', {
|
|
251
|
+
durationMs: Date.now() - batchStartedAt,
|
|
252
|
+
totalQueues: queues.length,
|
|
253
|
+
returnedQueues: stats.length,
|
|
254
|
+
usedBatchCounts: typeof driver.getJobCountsMany === 'function',
|
|
255
|
+
});
|
|
237
256
|
return {
|
|
238
257
|
status: 'ok',
|
|
239
258
|
startedAt,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/queue-monitor",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"description": "Queue monitoring package for ZinTrust with BullMQ and Redis.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"prepublishOnly": "npm run build"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"bullmq": "^5.
|
|
57
|
-
"ioredis": "^5.
|
|
56
|
+
"bullmq": "^5.77.6",
|
|
57
|
+
"ioredis": "^5.11.0"
|
|
58
58
|
}
|
|
59
59
|
}
|