@zintrust/queue-monitor 2.1.8 → 2.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/dist/driver.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { Env } from '@zintrust/core/config';
1
2
  import { ErrorFactory } from '@zintrust/core/errors';
2
3
  import { Logger } from '@zintrust/core/logger';
3
4
  import { getBullMQSafeQueueName } from '@zintrust/core/redis';
@@ -46,12 +47,26 @@ async function discoverQueuesFromRedis(redis, inMemoryQueues) {
46
47
  // eslint-disable-next-line max-lines-per-function
47
48
  export const createBullMQDriver = (config) => {
48
49
  const queues = new Map();
49
- const redis = createRedisConnection(config, 3, { subsystem: 'queue-monitor' });
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
+ }
50
66
  const getQueue = (name) => {
51
67
  if (!queues.has(name)) {
52
68
  const prefix = getBullMQSafeQueueName();
53
- const connection = createRedisConnection(config, 3, { subsystem: 'queue-monitor' });
54
- const queue = new Queue(name, { prefix, connection: connection });
69
+ const queue = new Queue(name, { prefix, connection: redis });
55
70
  queues.set(name, queue);
56
71
  }
57
72
  const queue = queues.get(name);
@@ -82,30 +97,37 @@ export const createBullMQDriver = (config) => {
82
97
  };
83
98
  const getJobCountsMany = async (queueNames) => {
84
99
  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,
100
+ const QUEUE_MONITOR_LOGGING_ENABLED = Env.getBool('QUEUE_MONITOR_LOGGING_ENABLED', false);
101
+ if (QUEUE_MONITOR_LOGGING_ENABLED) {
102
+ Logger.info('[queue-monitor] getJobCountsMany start', {
93
103
  requestedCount: queueNames.length,
94
104
  uniqueCount: uniqueQueueNames.length,
95
- pipelineCount: 0,
96
105
  });
106
+ }
107
+ const startedAt = Date.now();
108
+ if (uniqueQueueNames.length === 0) {
109
+ if (QUEUE_MONITOR_LOGGING_ENABLED) {
110
+ Logger.info('[queue-monitor] getJobCountsMany complete', {
111
+ durationMs: Date.now() - startedAt,
112
+ requestedCount: queueNames.length,
113
+ uniqueCount: uniqueQueueNames.length,
114
+ pipelineCount: 0,
115
+ });
116
+ }
97
117
  return [];
98
118
  }
99
119
  const stats = await Promise.all(uniqueQueueNames.map(async (name) => {
100
120
  const counts = await getJobCounts(name);
101
121
  return { name, counts };
102
122
  }));
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
- });
123
+ if (QUEUE_MONITOR_LOGGING_ENABLED) {
124
+ Logger.info('[queue-monitor] getJobCountsMany complete', {
125
+ durationMs: Date.now() - startedAt,
126
+ requestedCount: queueNames.length,
127
+ uniqueCount: uniqueQueueNames.length,
128
+ pipelineCount: uniqueQueueNames.length,
129
+ });
130
+ }
109
131
  return stats;
110
132
  };
111
133
  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.1.8",
3
+ "version": "2.2.0",
4
4
  "description": "Queue monitoring package for ZinTrust with BullMQ and Redis.",
5
5
  "private": false,
6
6
  "type": "module",