@zintrust/queue-monitor 2.9.0 → 3.0.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.
- package/dist/build-manifest.json +21 -29
- package/dist/dashboard-ui.js +42 -0
- package/dist/driver-index.d.ts +2 -2
- package/dist/driver-index.js +1 -1
- package/dist/driver.d.ts +15 -0
- package/dist/driver.js +95 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +44 -0
- package/package.json +4 -4
package/dist/build-manifest.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/queue-monitor",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"buildDate": "2026-
|
|
3
|
+
"version": "2.8.1",
|
|
4
|
+
"buildDate": "2026-06-27T08:39:10.255Z",
|
|
5
5
|
"buildEnvironment": {
|
|
6
|
-
"node": "
|
|
7
|
-
"platform": "
|
|
8
|
-
"arch": "
|
|
6
|
+
"node": "v22.22.1",
|
|
7
|
+
"platform": "darwin",
|
|
8
|
+
"arch": "arm64"
|
|
9
9
|
},
|
|
10
10
|
"git": {
|
|
11
|
-
"commit": "
|
|
12
|
-
"branch": "
|
|
11
|
+
"commit": "731f5512",
|
|
12
|
+
"branch": "release"
|
|
13
13
|
},
|
|
14
14
|
"package": {
|
|
15
15
|
"engines": {
|
|
@@ -33,14 +33,6 @@
|
|
|
33
33
|
"size": 721,
|
|
34
34
|
"sha256": "33e57f6cec15b8dcb5886ca92644139d2e3ca1789aae1c3a4a066d75a273a6bb"
|
|
35
35
|
},
|
|
36
|
-
"QueueEventStore.d.ts": {
|
|
37
|
-
"size": 1654,
|
|
38
|
-
"sha256": "d37915630d4ff4a36aac7521211fd439bc413e6821a3b960425695023d5dada7"
|
|
39
|
-
},
|
|
40
|
-
"QueueEventStore.js": {
|
|
41
|
-
"size": 13022,
|
|
42
|
-
"sha256": "83f0ba5bb0820691970a70ddb21b79202bbaf3f240ac3fa8fb5a35dee66ca9e4"
|
|
43
|
-
},
|
|
44
36
|
"QueueMonitoringService.d.ts": {
|
|
45
37
|
"size": 1760,
|
|
46
38
|
"sha256": "949569e78120329804b63736b25c8cff9b5516ca44c9e7f1b2989d9cb09360b9"
|
|
@@ -74,28 +66,28 @@
|
|
|
74
66
|
"sha256": "9f2b40d3921efbdb2ed84bd43b05bd7770b8af2c328448de6e0df1070c94860a"
|
|
75
67
|
},
|
|
76
68
|
"driver-index.d.ts": {
|
|
77
|
-
"size":
|
|
78
|
-
"sha256": "
|
|
69
|
+
"size": 311,
|
|
70
|
+
"sha256": "67cb3435d023bbb76ef968f722e2a6ff206a56d911671ba0d14504d04196cbe1"
|
|
79
71
|
},
|
|
80
72
|
"driver-index.js": {
|
|
81
|
-
"size":
|
|
82
|
-
"sha256": "
|
|
73
|
+
"size": 184,
|
|
74
|
+
"sha256": "fb91df973acd13a88cca443e50ecdd34944c66e1a1d48333f63099079a00f3c9"
|
|
83
75
|
},
|
|
84
76
|
"driver.d.ts": {
|
|
85
|
-
"size":
|
|
86
|
-
"sha256": "
|
|
77
|
+
"size": 1758,
|
|
78
|
+
"sha256": "967003567f92527f389046f7fbbf221146ae56254becc6c07a8c4e0e5261d954"
|
|
87
79
|
},
|
|
88
80
|
"driver.js": {
|
|
89
|
-
"size":
|
|
90
|
-
"sha256": "
|
|
81
|
+
"size": 16226,
|
|
82
|
+
"sha256": "b6125ade0a562d2bef8579e51b769b78de64e204dfc834aae729754d2922b323"
|
|
91
83
|
},
|
|
92
84
|
"index.d.ts": {
|
|
93
|
-
"size":
|
|
94
|
-
"sha256": "
|
|
85
|
+
"size": 2368,
|
|
86
|
+
"sha256": "ae9a03519f69648e9c71d4fbd1f00fb7aa27be714e10cc0786ea8696aea2b327"
|
|
95
87
|
},
|
|
96
88
|
"index.js": {
|
|
97
|
-
"size":
|
|
98
|
-
"sha256": "
|
|
89
|
+
"size": 18434,
|
|
90
|
+
"sha256": "d9ff26cf959ed0256ed932ab240a94ba4056a5b6af60850b30300d84176ea824"
|
|
99
91
|
},
|
|
100
92
|
"metrics-index.d.ts": {
|
|
101
93
|
"size": 239,
|
|
@@ -118,8 +110,8 @@
|
|
|
118
110
|
"sha256": "b4608f964f6c5cdb5469eb320683fee827734adcf1d03ea931766405451f35df"
|
|
119
111
|
},
|
|
120
112
|
"runtime-index.js": {
|
|
121
|
-
"size":
|
|
122
|
-
"sha256": "
|
|
113
|
+
"size": 9948,
|
|
114
|
+
"sha256": "7aa5c97aef19ec36e1309b9abc922481924672e4017bc3fe198b5eff7dabda86"
|
|
123
115
|
},
|
|
124
116
|
"worker.d.ts": {
|
|
125
117
|
"size": 347,
|
package/dist/dashboard-ui.js
CHANGED
|
@@ -112,6 +112,9 @@ html[data-theme="light"] .refresh-btn:hover { background: rgba(2, 132, 199, 0.16
|
|
|
112
112
|
.retry-btn { background: rgba(59, 130, 246, 0.1); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.3); padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 11px; font-weight: 600; transition: all 0.2s; }
|
|
113
113
|
.retry-btn:hover { background: rgba(59, 130, 246, 0.2); transform: scale(1.05); }
|
|
114
114
|
.retry-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
115
|
+
.requeue-btn { margin-right: 4px; }
|
|
116
|
+
.delete-btn { background: rgba(239, 68, 68, 0.12); color: #f87171; border-color: rgba(239, 68, 68, 0.35); }
|
|
117
|
+
.delete-btn:hover { background: rgba(239, 68, 68, 0.22); }
|
|
115
118
|
.recover-btn { background: rgba(245, 158, 11, 0.12); color: #fbbf24; border-color: rgba(245, 158, 11, 0.35); }
|
|
116
119
|
.recover-btn:hover { background: rgba(245, 158, 11, 0.2); }
|
|
117
120
|
|
|
@@ -580,6 +583,10 @@ const getRenderJobsIdentityHelpersFunction = () => `
|
|
|
580
583
|
if (status === 'failed') {
|
|
581
584
|
return '<button class="retry-btn" onclick="retryJob(' + "'" + job.id + "'" + ', ' + "'" + (job.queue || currentQueue) + "'" + ')" title="Retry this job">↻ Retry</button>';
|
|
582
585
|
}
|
|
586
|
+
if (status === 'waiting' || status === 'wait' || status === 'prioritized') {
|
|
587
|
+
return '<button class="retry-btn requeue-btn" onclick="requeueWaitingJob(' + "'" + job.id + "'" + ', ' + "'" + (job.queue || currentQueue) + "'" + ')" title="Remove this waiting job and enqueue a fresh copy">Requeue</button>' +
|
|
588
|
+
'<button class="retry-btn delete-btn" onclick="deleteWaitingJob(' + "'" + job.id + "'" + ', ' + "'" + (job.queue || currentQueue) + "'" + ')" title="Delete this waiting job">Delete</button>';
|
|
589
|
+
}
|
|
583
590
|
return '<span style="color: var(--muted); font-size: 11px;">—</span>';
|
|
584
591
|
}
|
|
585
592
|
`;
|
|
@@ -1068,6 +1075,39 @@ const getRecoverActiveJobFunction = () => `
|
|
|
1068
1075
|
btn.disabled = false;
|
|
1069
1076
|
}
|
|
1070
1077
|
}`;
|
|
1078
|
+
const getWaitingJobActionFunction = (name, path, busyLabel, doneLabel) => `
|
|
1079
|
+
async function ${name}(jobId, queueName) {
|
|
1080
|
+
const confirmed = window.confirm('${busyLabel} job ' + jobId + ' on ' + queueName + '?');
|
|
1081
|
+
if (!confirmed) return;
|
|
1082
|
+
try {
|
|
1083
|
+
const btn = event.target;
|
|
1084
|
+
btn.disabled = true;
|
|
1085
|
+
btn.textContent = '${busyLabel}...';
|
|
1086
|
+
|
|
1087
|
+
const res = await fetch(API_BASE + '${path}' + queueName + '/' + jobId, {
|
|
1088
|
+
method: 'POST'
|
|
1089
|
+
});
|
|
1090
|
+
const payload = await res.json().catch(() => null);
|
|
1091
|
+
|
|
1092
|
+
if (res.ok) {
|
|
1093
|
+
btn.textContent = payload && payload.newJobId ? '${doneLabel} ' + payload.newJobId : '${doneLabel}';
|
|
1094
|
+
setTimeout(() => {
|
|
1095
|
+
fetchData();
|
|
1096
|
+
}, 1000);
|
|
1097
|
+
} else {
|
|
1098
|
+
btn.textContent = 'Failed';
|
|
1099
|
+
btn.disabled = false;
|
|
1100
|
+
window.alert((payload && (payload.error || payload.message)) || 'Request failed');
|
|
1101
|
+
}
|
|
1102
|
+
} catch (e) {
|
|
1103
|
+
console.error('Failed waiting job action', e);
|
|
1104
|
+
const btn = event.target;
|
|
1105
|
+
btn.textContent = 'Failed';
|
|
1106
|
+
btn.disabled = false;
|
|
1107
|
+
}
|
|
1108
|
+
}`;
|
|
1109
|
+
const getDeleteWaitingJobFunction = () => getWaitingJobActionFunction('deleteWaitingJob', '/api/delete-waiting/', 'Delete', 'Deleted');
|
|
1110
|
+
const getRequeueWaitingJobFunction = () => getWaitingJobActionFunction('requeueWaitingJob', '/api/requeue-waiting/', 'Requeue', 'Requeued');
|
|
1071
1111
|
const getRetryJobFunction = () => `
|
|
1072
1112
|
async function retryJob(jobId, queueName) {
|
|
1073
1113
|
try {
|
|
@@ -1339,6 +1379,8 @@ const getDashboardScriptRender = () => [
|
|
|
1339
1379
|
getToggleDetailsFunctions(),
|
|
1340
1380
|
getRecoverActiveJobFunction(),
|
|
1341
1381
|
getRetryJobFunction(),
|
|
1382
|
+
getDeleteWaitingJobFunction(),
|
|
1383
|
+
getRequeueWaitingJobFunction(),
|
|
1342
1384
|
].join('\n');
|
|
1343
1385
|
const getDashboardScriptBootstrap = () => `
|
|
1344
1386
|
const themeButton = document.getElementById('theme-toggle');
|
package/dist/driver-index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Queue Monitor Driver - Runtime-only entrypoint
|
|
3
3
|
* Contains only the core queue driver functionality for production Workers
|
|
4
4
|
*/
|
|
5
|
-
export { createBullMQDriver, registerZedgiMonitorDriver } from './driver.js';
|
|
6
|
-
export type { JobCounts, JobPayload, QueueDriver, RecoverActiveJobResult, RetryJobResult, RetrySnapshot, } from './driver.js';
|
|
5
|
+
export { createBullMQDriver, isWaitingJobState, registerZedgiMonitorDriver } from './driver.js';
|
|
6
|
+
export type { JobCounts, JobPayload, QueueDriver, RecoverActiveJobResult, RetryJobResult, RetrySnapshot, WaitingJobActionResult, } from './driver.js';
|
package/dist/driver-index.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Queue Monitor Driver - Runtime-only entrypoint
|
|
3
3
|
* Contains only the core queue driver functionality for production Workers
|
|
4
4
|
*/
|
|
5
|
-
export { createBullMQDriver, registerZedgiMonitorDriver } from './driver.js';
|
|
5
|
+
export { createBullMQDriver, isWaitingJobState, registerZedgiMonitorDriver } from './driver.js';
|
package/dist/driver.d.ts
CHANGED
|
@@ -36,6 +36,18 @@ export type RecoverActiveJobResult = {
|
|
|
36
36
|
status: 'missing' | 'not_active' | 'not_recoverable';
|
|
37
37
|
reason?: string;
|
|
38
38
|
};
|
|
39
|
+
export type WaitingJobActionResult = {
|
|
40
|
+
ok: true;
|
|
41
|
+
status: 'removed';
|
|
42
|
+
} | {
|
|
43
|
+
ok: true;
|
|
44
|
+
status: 'requeued';
|
|
45
|
+
newJobId?: string;
|
|
46
|
+
} | {
|
|
47
|
+
ok: false;
|
|
48
|
+
status: 'missing' | 'not_waiting';
|
|
49
|
+
reason?: string;
|
|
50
|
+
};
|
|
39
51
|
export type QueueDriver = {
|
|
40
52
|
enqueue<T>(name: string, payload: T, options?: JobsOptions): Promise<string>;
|
|
41
53
|
getJob(queueName: string, jobId: string): Promise<Job | undefined>;
|
|
@@ -47,10 +59,13 @@ export type QueueDriver = {
|
|
|
47
59
|
getRecentJobs(queueName: string, limit?: number): Promise<Job[]>;
|
|
48
60
|
retryJob(queueName: string, jobId: string, snapshot?: RetrySnapshot): Promise<RetryJobResult>;
|
|
49
61
|
recoverActiveJob(queueName: string, jobId: string): Promise<RecoverActiveJobResult>;
|
|
62
|
+
deleteWaitingJob(queueName: string, jobId: string): Promise<WaitingJobActionResult>;
|
|
63
|
+
requeueWaitingJob(queueName: string, jobId: string): Promise<WaitingJobActionResult>;
|
|
50
64
|
getQueues(): Promise<string[]>;
|
|
51
65
|
close(): Promise<void>;
|
|
52
66
|
};
|
|
53
67
|
declare let registeredZedgiMonitorDriverFactory: ((config: unknown) => QueueDriver) | undefined;
|
|
54
68
|
export declare const registerZedgiMonitorDriver: (factory: typeof registeredZedgiMonitorDriverFactory) => void;
|
|
69
|
+
export declare const isWaitingJobState: (state: unknown) => boolean;
|
|
55
70
|
export declare const createBullMQDriver: (config: RedisConfig) => QueueDriver;
|
|
56
71
|
export {};
|
package/dist/driver.js
CHANGED
|
@@ -2,6 +2,7 @@ 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 { UnrecoverableError } from 'bullmq';
|
|
5
6
|
import { createRedisConnection } from './connection.js';
|
|
6
7
|
let QueueCtor;
|
|
7
8
|
const ensureBullmqLoaded = async () => {
|
|
@@ -27,7 +28,8 @@ export const registerZedgiMonitorDriver = (factory) => {
|
|
|
27
28
|
registeredZedgiMonitorDriverFactory = typeof factory === 'function' ? factory : undefined;
|
|
28
29
|
};
|
|
29
30
|
const shouldUseRedisRpcMonitorDriver = () => Env.USE_REDIS_PROXY === true && Env.get('REDIS_RPC_URL', '').trim() !== '';
|
|
30
|
-
const resolveActiveQueueConnection = () => Env.get('QUEUE_CONNECTION',
|
|
31
|
+
const resolveActiveQueueConnection = () => Env.get('QUEUE_CONNECTION', '').trim().toLowerCase() ||
|
|
32
|
+
Env.get('QUEUE_DRIVER', '').trim().toLowerCase();
|
|
31
33
|
const shouldUseZedgiMonitorDriver = () => registeredZedgiMonitorDriverFactory !== undefined &&
|
|
32
34
|
Env.getBool('USE_ZEDGI', false) &&
|
|
33
35
|
resolveActiveQueueConnection() === 'queue-zedgi';
|
|
@@ -132,6 +134,53 @@ const createRedisRpcRetryJob = async (queueName, jobId) => {
|
|
|
132
134
|
const client = await createRpcClient();
|
|
133
135
|
return client.queue('retryJob', { target: queueName, args: [jobId] });
|
|
134
136
|
};
|
|
137
|
+
const WAITING_JOB_STATES = new Set(['waiting', 'wait', 'prioritized']);
|
|
138
|
+
const normalizeJobState = (state) => typeof state === 'string' ? state.trim().toLowerCase() : '';
|
|
139
|
+
export const isWaitingJobState = (state) => WAITING_JOB_STATES.has(normalizeJobState(state));
|
|
140
|
+
const waitingStateRejection = (state) => ({
|
|
141
|
+
ok: false,
|
|
142
|
+
status: 'not_waiting',
|
|
143
|
+
reason: `Job is ${normalizeJobState(state) || 'unknown'}, not waiting`,
|
|
144
|
+
});
|
|
145
|
+
const cloneRequeueOptions = (opts) => {
|
|
146
|
+
const next = { ...(opts ?? {}) };
|
|
147
|
+
delete next.jobId;
|
|
148
|
+
return next;
|
|
149
|
+
};
|
|
150
|
+
const createRedisRpcDeleteWaitingJob = async (queueName, jobId) => {
|
|
151
|
+
const client = await createRpcClient();
|
|
152
|
+
const job = await client.queue('getJob', {
|
|
153
|
+
target: queueName,
|
|
154
|
+
args: [jobId],
|
|
155
|
+
});
|
|
156
|
+
if (!job)
|
|
157
|
+
return { ok: false, status: 'missing' };
|
|
158
|
+
if (!isWaitingJobState(job.state))
|
|
159
|
+
return waitingStateRejection(job.state);
|
|
160
|
+
await client.queue('removeJob', { target: queueName, args: [jobId] });
|
|
161
|
+
return { ok: true, status: 'removed' };
|
|
162
|
+
};
|
|
163
|
+
const createRedisRpcRequeueWaitingJob = async (queueName, jobId) => {
|
|
164
|
+
const client = await createRpcClient();
|
|
165
|
+
const job = await client.queue('getJob', {
|
|
166
|
+
target: queueName,
|
|
167
|
+
args: [jobId],
|
|
168
|
+
});
|
|
169
|
+
if (!job)
|
|
170
|
+
return { ok: false, status: 'missing' };
|
|
171
|
+
if (!isWaitingJobState(job.state))
|
|
172
|
+
return waitingStateRejection(job.state);
|
|
173
|
+
await client.queue('removeJob', { target: queueName, args: [jobId] });
|
|
174
|
+
const added = await client.queue('add', {
|
|
175
|
+
target: queueName,
|
|
176
|
+
args: [job.name ?? `${queueName}-job`, job.data ?? {}, cloneRequeueOptions(job.opts)],
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
ok: true,
|
|
180
|
+
status: 'requeued',
|
|
181
|
+
newJobId: added.id === undefined || added.id === null ? undefined : String(added.id),
|
|
182
|
+
};
|
|
183
|
+
};
|
|
135
184
|
const redisRpcRecoverActiveLockMs = () => Math.max(1, Env.getInt('QUEUE_MONITOR_RECOVER_ACTIVE_LOCK_MS', 30_000));
|
|
136
185
|
const redisRpcBullMqPrefix = () => Env.get('REDIS_RPC_BULLMQ_PREFIX', Env.get('BULLMQ_PREFIX', 'bull')).replace(/:+$/u, '');
|
|
137
186
|
const inspectRecoveredRedisRpcJob = async (client, queueName, jobId) => {
|
|
@@ -221,6 +270,8 @@ const createRedisRpcDriver = () => Object.freeze({
|
|
|
221
270
|
getRecentJobs: createRedisRpcRecentJobs,
|
|
222
271
|
retryJob: createRedisRpcRetryJob,
|
|
223
272
|
recoverActiveJob: createRedisRpcRecoverActiveJob,
|
|
273
|
+
deleteWaitingJob: createRedisRpcDeleteWaitingJob,
|
|
274
|
+
requeueWaitingJob: createRedisRpcRequeueWaitingJob,
|
|
224
275
|
getQueues: createRedisRpcGetQueues,
|
|
225
276
|
close: createRedisRpcClose,
|
|
226
277
|
});
|
|
@@ -419,6 +470,35 @@ const createBullMQRetryJob = (getQueue, getJob) => async (queueName, jobId, snap
|
|
|
419
470
|
};
|
|
420
471
|
}
|
|
421
472
|
};
|
|
473
|
+
const createBullMQDeleteWaitingJob = (getJob) => async (queueName, jobId) => {
|
|
474
|
+
const job = await getJob(queueName, jobId);
|
|
475
|
+
if (!job)
|
|
476
|
+
return { ok: false, status: 'missing' };
|
|
477
|
+
const state = await job.getState().catch(() => undefined);
|
|
478
|
+
if (!isWaitingJobState(state))
|
|
479
|
+
return waitingStateRejection(state);
|
|
480
|
+
await job.remove();
|
|
481
|
+
return { ok: true, status: 'removed' };
|
|
482
|
+
};
|
|
483
|
+
const createBullMQRequeueWaitingJob = (getQueue, getJob) => async (queueName, jobId) => {
|
|
484
|
+
const queue = await getQueue(queueName);
|
|
485
|
+
const job = await getJob(queueName, jobId);
|
|
486
|
+
if (!job)
|
|
487
|
+
return { ok: false, status: 'missing' };
|
|
488
|
+
const state = await job.getState().catch(() => undefined);
|
|
489
|
+
if (!isWaitingJobState(state))
|
|
490
|
+
return waitingStateRejection(state);
|
|
491
|
+
const name = job.name;
|
|
492
|
+
const data = job.data;
|
|
493
|
+
const opts = cloneRequeueOptions(job.opts);
|
|
494
|
+
await job.remove();
|
|
495
|
+
const requeued = await queue.add(name, data, opts);
|
|
496
|
+
return {
|
|
497
|
+
ok: true,
|
|
498
|
+
status: 'requeued',
|
|
499
|
+
newJobId: requeued.id === undefined || requeued.id === null ? undefined : String(requeued.id),
|
|
500
|
+
};
|
|
501
|
+
};
|
|
422
502
|
const createBullMQRecoverActiveJob = (getQueue, getJob) => async (queueName, jobId) => {
|
|
423
503
|
const queue = await getQueue(queueName);
|
|
424
504
|
const job = await getJob(queueName, jobId);
|
|
@@ -433,11 +513,9 @@ const createBullMQRecoverActiveJob = (getQueue, getJob) => async (queueName, job
|
|
|
433
513
|
};
|
|
434
514
|
}
|
|
435
515
|
try {
|
|
436
|
-
|
|
437
|
-
const queueWithClient = queue;
|
|
438
|
-
const client = await queueWithClient.client;
|
|
516
|
+
const client = (await queue.getBackend().client);
|
|
439
517
|
await client.set(queue.toKey(jobId) + ':lock', 'pull-worker', 'PX', String(Math.max(1, Env.getInt('QUEUE_MONITOR_RECOVER_ACTIVE_LOCK_MS', 30_000))));
|
|
440
|
-
await job.moveToFailed(new
|
|
518
|
+
await job.moveToFailed(new UnrecoverableError('manual queue-monitor stale active recovery'), 'pull-worker', false);
|
|
441
519
|
return { ok: true, status: 'failed' };
|
|
442
520
|
}
|
|
443
521
|
catch (error) {
|
|
@@ -450,7 +528,16 @@ const createBullMQRecoverActiveJob = (getQueue, getJob) => async (queueName, job
|
|
|
450
528
|
};
|
|
451
529
|
const createBullMQGetRecentJobs = (getQueue) => async (queueName, limit = 100) => {
|
|
452
530
|
const queue = await getQueue(queueName);
|
|
453
|
-
const jobs = await queue.getJobs([
|
|
531
|
+
const jobs = await queue.getJobs([
|
|
532
|
+
'completed',
|
|
533
|
+
'failed',
|
|
534
|
+
'active',
|
|
535
|
+
'waiting',
|
|
536
|
+
'delayed',
|
|
537
|
+
'prioritized',
|
|
538
|
+
'waiting-children',
|
|
539
|
+
'wait',
|
|
540
|
+
], 0, Math.max(0, limit - 1), true);
|
|
454
541
|
await enrichJobsWithState(jobs);
|
|
455
542
|
return jobs;
|
|
456
543
|
};
|
|
@@ -481,6 +568,8 @@ export const createBullMQDriver = (config) => {
|
|
|
481
568
|
getRecentJobs: createBullMQGetRecentJobs(getQueue),
|
|
482
569
|
retryJob: createBullMQRetryJob(getQueue, createBullMQGetJob(getQueue)),
|
|
483
570
|
recoverActiveJob: createBullMQRecoverActiveJob(getQueue, createBullMQGetJob(getQueue)),
|
|
571
|
+
deleteWaitingJob: createBullMQDeleteWaitingJob(createBullMQGetJob(getQueue)),
|
|
572
|
+
requeueWaitingJob: createBullMQRequeueWaitingJob(getQueue, createBullMQGetJob(getQueue)),
|
|
484
573
|
getQueues: createBullMQGetQueues(redis, queues),
|
|
485
574
|
close: createBullMQClose(queues),
|
|
486
575
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type Metrics } from './metrics.js';
|
|
|
5
5
|
export { getRecentJobsForQueue, getRecentJobsForSelection, QueueMonitoringService, QueueMonitoringStream, } from './QueueMonitoringService.js';
|
|
6
6
|
export { QueueEventStore } from './QueueEventStore.js';
|
|
7
7
|
export { createBullMQDriver, registerZedgiMonitorDriver } from './driver.js';
|
|
8
|
-
export type { JobPayload, QueueDriver, RecoverActiveJobResult } from './driver.js';
|
|
8
|
+
export type { JobPayload, QueueDriver, RecoverActiveJobResult, WaitingJobActionResult, } from './driver.js';
|
|
9
9
|
export { createMetrics, type JobStatus, type JobSummary, type Metrics } from './metrics.js';
|
|
10
10
|
export { createWorker as createQueueWorker, type QueueWorker } from './worker.js';
|
|
11
11
|
export type QueueMonitorConfig = {
|
package/dist/index.js
CHANGED
|
@@ -250,6 +250,39 @@ async function handleRecoverActiveEndpoint(req, res, driver) {
|
|
|
250
250
|
status: result.status,
|
|
251
251
|
});
|
|
252
252
|
}
|
|
253
|
+
function extractJobRouteParams(req) {
|
|
254
|
+
const queueName = extractQueueParam(req);
|
|
255
|
+
const jobId = typeof req.getParam === 'function' ? req.getParam?.('jobId') : req.params?.['jobId'];
|
|
256
|
+
return {
|
|
257
|
+
queueName: queueName ?? '',
|
|
258
|
+
jobId: typeof jobId === 'string' ? jobId : '',
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
async function handleWaitingJobActionEndpoint(req, res, action, successMessage) {
|
|
262
|
+
const { queueName, jobId } = extractJobRouteParams(req);
|
|
263
|
+
if (!queueName || !jobId) {
|
|
264
|
+
res.status(400).json(fieldError('queue_name,job_id', 'Queue name and job ID must be provided'));
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const result = await action(queueName, jobId);
|
|
268
|
+
if (result.ok) {
|
|
269
|
+
res.json({
|
|
270
|
+
ok: true,
|
|
271
|
+
status: result.status,
|
|
272
|
+
message: successMessage(jobId, result),
|
|
273
|
+
...(result.status === 'requeued' && result.newJobId ? { newJobId: result.newJobId } : {}),
|
|
274
|
+
});
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (result.status === 'missing') {
|
|
278
|
+
res.status(404).json({ error: `Job ${jobId} no longer exists`, status: result.status });
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
res.status(409).json({
|
|
282
|
+
error: result.reason ?? `Job ${jobId} cannot be changed in its current state`,
|
|
283
|
+
status: result.status,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
253
286
|
function buildSettings(config) {
|
|
254
287
|
return {
|
|
255
288
|
enabled: config.enabled ?? DEFAULTS.enabled,
|
|
@@ -364,6 +397,7 @@ function registerApiRoutes(router, settings, routeOptions, metrics, driver, getS
|
|
|
364
397
|
registerLocksApi(router, settings, routeOptions, getLocks);
|
|
365
398
|
registerRetryApi(router, settings, routeOptions, driver, metrics);
|
|
366
399
|
registerRecoverActiveApi(router, settings, routeOptions, driver);
|
|
400
|
+
registerWaitingJobApi(router, settings, routeOptions, driver);
|
|
367
401
|
registerEventsApi(router, settings, routeOptions, getSnapshot, getLocks, metrics, driver);
|
|
368
402
|
}
|
|
369
403
|
function registerSnapshotApi(router, settings, routeOptions, getSnapshot) {
|
|
@@ -392,6 +426,16 @@ function registerRetryApi(router, settings, routeOptions, driver, metrics) {
|
|
|
392
426
|
await handleRetryEndpoint(req, res, driver, metrics);
|
|
393
427
|
}, routeOptions);
|
|
394
428
|
}
|
|
429
|
+
function registerWaitingJobApi(router, settings, routeOptions, driver) {
|
|
430
|
+
Router.post(router, `${settings.basePath}/api/delete-waiting/:queue/:jobId`, async (req, res) => {
|
|
431
|
+
await handleWaitingJobActionEndpoint(req, res, (queueName, jobId) => driver.deleteWaitingJob(queueName, jobId), (jobId) => `Waiting job ${jobId} deleted`);
|
|
432
|
+
}, routeOptions);
|
|
433
|
+
Router.post(router, `${settings.basePath}/api/requeue-waiting/:queue/:jobId`, async (req, res) => {
|
|
434
|
+
await handleWaitingJobActionEndpoint(req, res, (queueName, jobId) => driver.requeueWaitingJob(queueName, jobId), (jobId, result) => result.status === 'requeued' && result.newJobId
|
|
435
|
+
? `Waiting job ${jobId} requeued as ${result.newJobId}`
|
|
436
|
+
: `Waiting job ${jobId} requeued`);
|
|
437
|
+
}, routeOptions);
|
|
438
|
+
}
|
|
395
439
|
function registerRecoverActiveApi(router, settings, routeOptions, driver) {
|
|
396
440
|
Router.post(router, `${settings.basePath}/api/recover-active/:queue/:jobId`, async (req, res) => {
|
|
397
441
|
await handleRecoverActiveEndpoint(req, res, driver);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/queue-monitor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Queue monitoring package for ZinTrust with BullMQ and Redis.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"prepublishOnly": "npm run build"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"bullmq": "^
|
|
63
|
-
"ioredis": "^
|
|
62
|
+
"bullmq": "^6.3.1",
|
|
63
|
+
"ioredis": "^6.0.0"
|
|
64
64
|
}
|
|
65
|
-
}
|
|
65
|
+
}
|