@zintrust/queue-monitor 2.4.4 → 2.4.5
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 +0 -9
- package/dist/driver.js +204 -200
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +4 -2
- package/package.json +1 -1
package/dist/driver.d.ts
CHANGED
|
@@ -2,16 +2,7 @@ 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
5
|
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
6
|
export declare const emptyQueueStats: (queueNames: ReadonlyArray<string>) => Array<{
|
|
16
7
|
name: string;
|
|
17
8
|
counts: JobCounts;
|
package/dist/driver.js
CHANGED
|
@@ -2,13 +2,16 @@ import { Env } from '@zintrust/core/config';
|
|
|
2
2
|
import { ErrorFactory } from '@zintrust/core/errors';
|
|
3
3
|
import { Logger } from '@zintrust/core/logger';
|
|
4
4
|
import { getBullMQSafeQueueName } from '@zintrust/core/redis';
|
|
5
|
-
import { Queue } from 'bullmq';
|
|
6
5
|
import { createRedisConnection } from './connection.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
let QueueCtor;
|
|
7
|
+
const ensureBullmqLoaded = async () => {
|
|
8
|
+
if (QueueCtor !== undefined)
|
|
9
|
+
return QueueCtor;
|
|
10
|
+
const bullmqPkg = 'bullmq';
|
|
11
|
+
const loaded = (await import(bullmqPkg)).Queue;
|
|
12
|
+
QueueCtor = loaded;
|
|
13
|
+
return loaded;
|
|
14
|
+
};
|
|
12
15
|
export const emptyCounts = () => ({
|
|
13
16
|
waiting: 0,
|
|
14
17
|
active: 0,
|
|
@@ -17,10 +20,6 @@ export const emptyCounts = () => ({
|
|
|
17
20
|
delayed: 0,
|
|
18
21
|
paused: 0,
|
|
19
22
|
});
|
|
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
23
|
export const emptyQueueStats = (queueNames) => queueNames.map((name) => ({ name, counts: emptyCounts() }));
|
|
25
24
|
const shouldUseRedisRpcMonitorDriver = () => Env.USE_REDIS_PROXY === true && Env.get('REDIS_RPC_URL', '').trim() !== '';
|
|
26
25
|
const resolveRpcBaseUrl = () => {
|
|
@@ -66,83 +65,88 @@ const createRpcClient = async () => Object.freeze({
|
|
|
66
65
|
queue: (method, payload = {}) => callRedisRpc('queue', method, payload),
|
|
67
66
|
monitor: (method, payload = {}) => callRedisRpc('queue-monitor', method, payload),
|
|
68
67
|
});
|
|
69
|
-
const
|
|
70
|
-
const
|
|
68
|
+
const createRedisRpcEnqueue = async (name, payload, options) => {
|
|
69
|
+
const client = await createRpcClient();
|
|
70
|
+
const result = await client.queue('add', {
|
|
71
|
+
target: name,
|
|
72
|
+
args: ['default', payload, options ?? {}],
|
|
73
|
+
});
|
|
74
|
+
if (result.id === undefined || result.id === null) {
|
|
75
|
+
throw ErrorFactory.createTryCatchError(`Queue job id missing for ${name}`);
|
|
76
|
+
}
|
|
77
|
+
return String(result.id);
|
|
78
|
+
};
|
|
79
|
+
const createRedisRpcGetJob = async (queueName, jobId) => {
|
|
80
|
+
const client = await createRpcClient();
|
|
81
|
+
try {
|
|
82
|
+
return await client.queue('getJob', { target: queueName, args: [jobId] });
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
Logger.warn('[queue-monitor] Redis RPC job lookup failed; returning no job', error);
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const createRedisRpcGetJobCounts = async (queueName) => {
|
|
90
|
+
try {
|
|
71
91
|
const client = await createRpcClient();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
92
|
+
return client.queue('getJobCounts', { target: queueName });
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
Logger.warn('[queue-monitor] Redis RPC job counts failed; returning empty counts', error);
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const createRedisRpcGetJobCountsMany = async (queueNames) => {
|
|
100
|
+
const client = await createRpcClient();
|
|
101
|
+
try {
|
|
102
|
+
const snapshot = await client.monitor('getSnapshot', { args: [queueNames] });
|
|
103
|
+
return snapshot.queues ?? emptyQueueStats(queueNames);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
Logger.warn('[queue-monitor] Redis RPC batch counts failed; returning known queues with empty counts', error);
|
|
107
|
+
return emptyQueueStats(queueNames);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const createRedisRpcRecentJobs = async (queueName, limit = 100) => {
|
|
111
|
+
const client = await createRpcClient();
|
|
112
|
+
try {
|
|
113
|
+
return await client.monitor('getRecentJobsForQueue', {
|
|
114
|
+
args: [queueName, limit],
|
|
75
115
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Logger.warn('[queue-monitor] Redis RPC job counts failed; returning empty counts', error);
|
|
100
|
-
return {};
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
async getJobCountsMany(queueNames) {
|
|
104
|
-
const client = await createRpcClient();
|
|
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
|
-
}
|
|
113
|
-
},
|
|
114
|
-
async getRecentJobs(queueName, limit = 100) {
|
|
115
|
-
const client = await createRpcClient();
|
|
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
|
-
}
|
|
125
|
-
},
|
|
126
|
-
async retryJob(queueName, jobId) {
|
|
127
|
-
const client = await createRpcClient();
|
|
128
|
-
return client.queue('retryJob', { target: queueName, args: [jobId] });
|
|
129
|
-
},
|
|
130
|
-
async getQueues() {
|
|
131
|
-
const client = await createRpcClient();
|
|
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
|
-
}
|
|
140
|
-
},
|
|
141
|
-
async close() {
|
|
142
|
-
await Promise.resolve();
|
|
143
|
-
},
|
|
144
|
-
});
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
Logger.warn('[queue-monitor] Redis RPC recent jobs failed; returning no jobs', error);
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const createRedisRpcRetryJob = async (queueName, jobId) => {
|
|
123
|
+
const client = await createRpcClient();
|
|
124
|
+
return client.queue('retryJob', { target: queueName, args: [jobId] });
|
|
125
|
+
};
|
|
126
|
+
const createRedisRpcGetQueues = async () => {
|
|
127
|
+
const client = await createRpcClient();
|
|
128
|
+
try {
|
|
129
|
+
const snapshot = await client.monitor('getSnapshot');
|
|
130
|
+
return (snapshot.queues ?? []).map((queue) => queue.name);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
Logger.warn('[queue-monitor] Redis RPC queue discovery failed; returning no queues', error);
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const createRedisRpcClose = async () => {
|
|
138
|
+
await Promise.resolve();
|
|
145
139
|
};
|
|
140
|
+
const createRedisRpcDriver = () => Object.freeze({
|
|
141
|
+
enqueue: createRedisRpcEnqueue,
|
|
142
|
+
getJob: createRedisRpcGetJob,
|
|
143
|
+
getJobCounts: createRedisRpcGetJobCounts,
|
|
144
|
+
getJobCountsMany: createRedisRpcGetJobCountsMany,
|
|
145
|
+
getRecentJobs: createRedisRpcRecentJobs,
|
|
146
|
+
retryJob: createRedisRpcRetryJob,
|
|
147
|
+
getQueues: createRedisRpcGetQueues,
|
|
148
|
+
close: createRedisRpcClose,
|
|
149
|
+
});
|
|
146
150
|
async function enrichJobsWithState(jobs) {
|
|
147
151
|
await Promise.all(jobs.map(async (job) => {
|
|
148
152
|
try {
|
|
@@ -183,18 +187,12 @@ async function discoverQueuesFromRedis(redis, inMemoryQueues) {
|
|
|
183
187
|
}
|
|
184
188
|
return Array.from(found.values());
|
|
185
189
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (shouldUseRedisRpcMonitorDriver())
|
|
189
|
-
return createRedisRpcDriver();
|
|
190
|
-
const queues = new Map();
|
|
191
|
-
const redis = createRedisConnection(config, 3, {
|
|
192
|
-
subsystem: 'queue-monitor',
|
|
193
|
-
});
|
|
194
|
-
const getQueue = (name) => {
|
|
190
|
+
const createBullMQQueueGetter = (queues, redis) => {
|
|
191
|
+
return async (name) => {
|
|
195
192
|
if (!queues.has(name)) {
|
|
193
|
+
const QueueCtor = await ensureBullmqLoaded();
|
|
196
194
|
const prefix = getBullMQSafeQueueName();
|
|
197
|
-
const queue = new
|
|
195
|
+
const queue = new QueueCtor(name, { prefix, connection: redis });
|
|
198
196
|
queues.set(name, queue);
|
|
199
197
|
}
|
|
200
198
|
const queue = queues.get(name);
|
|
@@ -203,120 +201,126 @@ export const createBullMQDriver = (config) => {
|
|
|
203
201
|
}
|
|
204
202
|
return queue;
|
|
205
203
|
};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
204
|
+
};
|
|
205
|
+
const createBullMQEnqueue = (getQueue) => async (name, payload, options) => {
|
|
206
|
+
const queue = await getQueue(name);
|
|
207
|
+
const job = await queue.add('default', payload, {
|
|
208
|
+
removeOnComplete: true,
|
|
209
|
+
removeOnFail: false,
|
|
210
|
+
...options,
|
|
211
|
+
});
|
|
212
|
+
if (job.id === undefined || job.id === null) {
|
|
213
|
+
throw ErrorFactory.createTryCatchError(`Queue job id missing for ${name}`);
|
|
214
|
+
}
|
|
215
|
+
return String(job.id);
|
|
216
|
+
};
|
|
217
|
+
const createBullMQGetJob = (getQueue) => async (queueName, jobId) => {
|
|
218
|
+
const queue = await getQueue(queueName);
|
|
219
|
+
return (await queue.getJob(jobId)) || undefined;
|
|
220
|
+
};
|
|
221
|
+
const createBullMQGetJobCounts = (getQueue) => async (queueName) => {
|
|
222
|
+
const queue = await getQueue(queueName);
|
|
223
|
+
return queue.getJobCounts();
|
|
224
|
+
};
|
|
225
|
+
const createBullMQGetJobCountsMany = (getJobCounts) => async (queueNames) => {
|
|
226
|
+
const uniqueQueueNames = Array.from(new Set(queueNames.filter((queueName) => typeof queueName === 'string' && queueName.trim().length > 0)));
|
|
227
|
+
const QUEUE_MONITOR_LOGGING_ENABLED = Env.getBool('QUEUE_MONITOR_LOGGING_ENABLED', false);
|
|
228
|
+
if (QUEUE_MONITOR_LOGGING_ENABLED) {
|
|
229
|
+
Logger.info('[queue-monitor] getJobCountsMany start', {
|
|
230
|
+
requestedCount: queueNames.length,
|
|
231
|
+
uniqueCount: uniqueQueueNames.length,
|
|
212
232
|
});
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return String(job.id);
|
|
217
|
-
};
|
|
218
|
-
const getJob = async (queueName, jobId) => {
|
|
219
|
-
const queue = getQueue(queueName);
|
|
220
|
-
return (await queue.getJob(jobId)) || undefined;
|
|
221
|
-
};
|
|
222
|
-
const getJobCounts = async (queueName) => {
|
|
223
|
-
const queue = getQueue(queueName);
|
|
224
|
-
return queue.getJobCounts();
|
|
225
|
-
};
|
|
226
|
-
const getJobCountsMany = async (queueNames) => {
|
|
227
|
-
const uniqueQueueNames = Array.from(new Set(queueNames.filter((queueName) => typeof queueName === 'string' && queueName.trim().length > 0)));
|
|
228
|
-
const QUEUE_MONITOR_LOGGING_ENABLED = Env.getBool('QUEUE_MONITOR_LOGGING_ENABLED', false);
|
|
229
|
-
if (QUEUE_MONITOR_LOGGING_ENABLED) {
|
|
230
|
-
Logger.info('[queue-monitor] getJobCountsMany start', {
|
|
231
|
-
requestedCount: queueNames.length,
|
|
232
|
-
uniqueCount: uniqueQueueNames.length,
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
const startedAt = Date.now();
|
|
236
|
-
if (uniqueQueueNames.length === 0) {
|
|
237
|
-
if (QUEUE_MONITOR_LOGGING_ENABLED) {
|
|
238
|
-
Logger.info('[queue-monitor] getJobCountsMany complete', {
|
|
239
|
-
durationMs: Date.now() - startedAt,
|
|
240
|
-
requestedCount: queueNames.length,
|
|
241
|
-
uniqueCount: uniqueQueueNames.length,
|
|
242
|
-
pipelineCount: 0,
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
return [];
|
|
246
|
-
}
|
|
247
|
-
const stats = await Promise.all(uniqueQueueNames.map(async (name) => {
|
|
248
|
-
const counts = await getJobCounts(name);
|
|
249
|
-
return { name, counts };
|
|
250
|
-
}));
|
|
233
|
+
}
|
|
234
|
+
const startedAt = Date.now();
|
|
235
|
+
if (uniqueQueueNames.length === 0) {
|
|
251
236
|
if (QUEUE_MONITOR_LOGGING_ENABLED) {
|
|
252
237
|
Logger.info('[queue-monitor] getJobCountsMany complete', {
|
|
253
238
|
durationMs: Date.now() - startedAt,
|
|
254
239
|
requestedCount: queueNames.length,
|
|
255
240
|
uniqueCount: uniqueQueueNames.length,
|
|
256
|
-
pipelineCount:
|
|
241
|
+
pipelineCount: 0,
|
|
257
242
|
});
|
|
258
243
|
}
|
|
259
|
-
return
|
|
260
|
-
}
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
244
|
+
return [];
|
|
245
|
+
}
|
|
246
|
+
const stats = await Promise.all(uniqueQueueNames.map(async (name) => {
|
|
247
|
+
const counts = await getJobCounts(name);
|
|
248
|
+
return { name, counts };
|
|
249
|
+
}));
|
|
250
|
+
if (QUEUE_MONITOR_LOGGING_ENABLED) {
|
|
251
|
+
Logger.info('[queue-monitor] getJobCountsMany complete', {
|
|
252
|
+
durationMs: Date.now() - startedAt,
|
|
253
|
+
requestedCount: queueNames.length,
|
|
254
|
+
uniqueCount: uniqueQueueNames.length,
|
|
255
|
+
pipelineCount: uniqueQueueNames.length,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return stats;
|
|
259
|
+
};
|
|
260
|
+
const createBullMQRequeueFromSnapshot = (queue) => async (snapshot) => {
|
|
261
|
+
try {
|
|
262
|
+
const requeued = await queue.add(snapshot.name ?? 'default', snapshot.data, snapshot.opts);
|
|
263
|
+
return {
|
|
264
|
+
ok: true,
|
|
265
|
+
status: 'requeued_from_snapshot',
|
|
266
|
+
newJobId: requeued.id === undefined || requeued.id === null ? undefined : String(requeued.id),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
return {
|
|
271
|
+
ok: false,
|
|
272
|
+
status: 'not_retryable',
|
|
273
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
const createBullMQRetryJob = (getQueue, getJob) => async (queueName, jobId, snapshot) => {
|
|
278
|
+
const queue = await getQueue(queueName);
|
|
279
|
+
const job = await getJob(queueName, jobId);
|
|
280
|
+
if (!job) {
|
|
281
|
+
if (snapshot)
|
|
282
|
+
return createBullMQRequeueFromSnapshot(queue)(snapshot);
|
|
283
|
+
return { ok: false, status: 'missing' };
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
await job.retry();
|
|
287
|
+
return { ok: true, status: 'retried' };
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
return {
|
|
291
|
+
ok: false,
|
|
292
|
+
status: 'not_retryable',
|
|
293
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
const createBullMQGetRecentJobs = (getQueue) => async (queueName, limit = 100) => {
|
|
298
|
+
const queue = await getQueue(queueName);
|
|
299
|
+
const jobs = await queue.getJobs(['completed', 'failed', 'active', 'waiting', 'delayed', 'paused'], 0, Math.max(0, limit - 1), true);
|
|
300
|
+
await enrichJobsWithState(jobs);
|
|
301
|
+
return jobs;
|
|
302
|
+
};
|
|
303
|
+
const createBullMQGetQueues = (redis, queues) => async () => discoverQueuesFromRedis(redis, queues);
|
|
304
|
+
const createBullMQClose = (queues) => async () => {
|
|
305
|
+
const closes = Array.from(queues.values()).map((q) => q.close());
|
|
306
|
+
await Promise.all(closes);
|
|
307
|
+
};
|
|
308
|
+
export const createBullMQDriver = (config) => {
|
|
309
|
+
if (shouldUseRedisRpcMonitorDriver())
|
|
310
|
+
return createRedisRpcDriver();
|
|
311
|
+
const queues = new Map();
|
|
312
|
+
const redis = createRedisConnection(config, 3, {
|
|
313
|
+
subsystem: 'queue-monitor',
|
|
314
|
+
});
|
|
315
|
+
const getQueue = createBullMQQueueGetter(queues, redis);
|
|
312
316
|
return Object.freeze({
|
|
313
|
-
enqueue,
|
|
314
|
-
getJob,
|
|
315
|
-
getJobCounts,
|
|
316
|
-
getJobCountsMany,
|
|
317
|
-
getRecentJobs,
|
|
318
|
-
retryJob,
|
|
319
|
-
getQueues,
|
|
320
|
-
close,
|
|
317
|
+
enqueue: createBullMQEnqueue(getQueue),
|
|
318
|
+
getJob: createBullMQGetJob(getQueue),
|
|
319
|
+
getJobCounts: createBullMQGetJobCounts(getQueue),
|
|
320
|
+
getJobCountsMany: createBullMQGetJobCountsMany(createBullMQGetJobCounts(getQueue)),
|
|
321
|
+
getRecentJobs: createBullMQGetRecentJobs(getQueue),
|
|
322
|
+
retryJob: createBullMQRetryJob(getQueue, createBullMQGetJob(getQueue)),
|
|
323
|
+
getQueues: createBullMQGetQueues(redis, queues),
|
|
324
|
+
close: createBullMQClose(queues),
|
|
321
325
|
});
|
|
322
326
|
};
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Processor } from 'bullmq';
|
|
2
2
|
import { type RedisConfig } from './connection.js';
|
|
3
3
|
import type { Metrics } from './metrics.js';
|
|
4
4
|
export type QueueWorker = {
|
|
5
5
|
close: () => Promise<void>;
|
|
6
6
|
};
|
|
7
|
-
export declare const createWorker: (queueName: string, processor: Processor, redisConfig: RedisConfig, metrics: Metrics) => QueueWorker
|
|
7
|
+
export declare const createWorker: (queueName: string, processor: Processor, redisConfig: RedisConfig, metrics: Metrics) => Promise<QueueWorker>;
|
package/dist/worker.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { getBullMQSafeQueueName } from '@zintrust/core/redis';
|
|
2
|
-
import { Worker } from 'bullmq';
|
|
3
2
|
import { createRedisConnection } from './connection.js';
|
|
4
|
-
export const createWorker = (queueName, processor, redisConfig, metrics) => {
|
|
3
|
+
export const createWorker = async (queueName, processor, redisConfig, metrics) => {
|
|
5
4
|
const connection = createRedisConnection(redisConfig, 3, { subsystem: 'queue-monitor-worker' });
|
|
6
5
|
const prefix = getBullMQSafeQueueName();
|
|
6
|
+
// Variable specifier so bundlers do not inline bullmq into the Workers bundle.
|
|
7
|
+
const bullmqPkg = 'bullmq';
|
|
8
|
+
const { Worker } = await import(bullmqPkg);
|
|
7
9
|
const worker = new Worker(queueName, processor, {
|
|
8
10
|
connection: connection,
|
|
9
11
|
prefix,
|