@zintrust/queue-monitor 2.4.5 → 2.4.7
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 +16 -16
- package/dist/dashboard-ui.js +50 -5
- package/dist/driver-index.d.ts +1 -1
- package/dist/driver.d.ts +10 -0
- package/dist/driver.js +99 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -0
- package/package.json +1 -1
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-06-
|
|
3
|
+
"version": "2.4.6",
|
|
4
|
+
"buildDate": "2026-06-11T20:48:32.186Z",
|
|
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": "5a1a7000",
|
|
12
12
|
"branch": "release"
|
|
13
13
|
},
|
|
14
14
|
"package": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"sha256": "3b7e85e6a0ba5dd958010bdf023052b1fb66cfbb52047554b326b4465b817719"
|
|
43
43
|
},
|
|
44
44
|
"build-manifest.json": {
|
|
45
|
-
"size":
|
|
46
|
-
"sha256": "
|
|
45
|
+
"size": 3871,
|
|
46
|
+
"sha256": "e528885f6647e617d567e6e7231f1abef4878bfee18c4a0b1cae7172984162cc"
|
|
47
47
|
},
|
|
48
48
|
"connection.d.ts": {
|
|
49
49
|
"size": 287,
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"sha256": "5140191207b5620500ac5e1edacefed65956a1ad88739695d545ea7d2b405243"
|
|
67
67
|
},
|
|
68
68
|
"dashboard-ui.js": {
|
|
69
|
-
"size":
|
|
70
|
-
"sha256": "
|
|
69
|
+
"size": 54132,
|
|
70
|
+
"sha256": "1a017b07922c7f37e4717547b2d97cfb76b2460a4f3c9659ec9e5c2a41ebf889"
|
|
71
71
|
},
|
|
72
72
|
"driver-index.d.ts": {
|
|
73
73
|
"size": 287,
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
"sha256": "fb91df973acd13a88cca443e50ecdd34944c66e1a1d48333f63099079a00f3c9"
|
|
79
79
|
},
|
|
80
80
|
"driver.d.ts": {
|
|
81
|
-
"size":
|
|
82
|
-
"sha256": "
|
|
81
|
+
"size": 1417,
|
|
82
|
+
"sha256": "9aa9e6ac31d8a0a3d4145a8228bd61180be89e7170b02d1290fcb732a4c217a1"
|
|
83
83
|
},
|
|
84
84
|
"driver.js": {
|
|
85
|
-
"size":
|
|
86
|
-
"sha256": "
|
|
85
|
+
"size": 12508,
|
|
86
|
+
"sha256": "c77e609af5d2c05b96fd5512c9597cb5e37c3e7a187cf8face4c94ce7fbc7990"
|
|
87
87
|
},
|
|
88
88
|
"index.d.ts": {
|
|
89
89
|
"size": 2344,
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
},
|
|
92
92
|
"index.js": {
|
|
93
93
|
"size": 17226,
|
|
94
|
-
"sha256": "
|
|
94
|
+
"sha256": "ea914e117c67999b35ebe5da07af9e4301a9360f522645be918ef3c541d1fa5c"
|
|
95
95
|
},
|
|
96
96
|
"metrics-index.d.ts": {
|
|
97
97
|
"size": 239,
|
|
@@ -118,12 +118,12 @@
|
|
|
118
118
|
"sha256": "7aa5c97aef19ec36e1309b9abc922481924672e4017bc3fe198b5eff7dabda86"
|
|
119
119
|
},
|
|
120
120
|
"worker.d.ts": {
|
|
121
|
-
"size":
|
|
122
|
-
"sha256": "
|
|
121
|
+
"size": 347,
|
|
122
|
+
"sha256": "fb7751246ae88f5f470107e35f25f561da5919fd2619fe70b8b182d0c878ac0e"
|
|
123
123
|
},
|
|
124
124
|
"worker.js": {
|
|
125
|
-
"size":
|
|
126
|
-
"sha256": "
|
|
125
|
+
"size": 1376,
|
|
126
|
+
"sha256": "4f114198579d049482e284738cbdf35576d48bb269cc0936053911548efacb5d"
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
}
|
package/dist/dashboard-ui.js
CHANGED
|
@@ -112,6 +112,8 @@ 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
|
+
.recover-btn { background: rgba(245, 158, 11, 0.12); color: #fbbf24; border-color: rgba(245, 158, 11, 0.35); }
|
|
116
|
+
.recover-btn:hover { background: rgba(245, 158, 11, 0.2); }
|
|
115
117
|
|
|
116
118
|
#error-container { display: none; margin-bottom: 2rem; padding: 1rem; background: rgba(239, 68, 68, 0.1); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.2); border-radius: 0.5rem; font-size: 13px; font-weight: 600; }
|
|
117
119
|
code { background: rgba(0,0,0,0.3); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 12px; color: var(--accent); border: 1px solid var(--border); }
|
|
@@ -550,6 +552,9 @@ const getRenderJobsIdentityHelpersFunction = () => `
|
|
|
550
552
|
|
|
551
553
|
function getJobRetryMarkup(job) {
|
|
552
554
|
const status = (job.status || (job.failedReason ? 'failed' : 'completed')).toLowerCase();
|
|
555
|
+
if (status === 'active') {
|
|
556
|
+
return '<button class="retry-btn recover-btn" onclick="recoverActiveJob(' + "'" + job.id + "'" + ', ' + "'" + (job.queue || currentQueue) + "'" + ')" title="Recover this active job">Recover</button>';
|
|
557
|
+
}
|
|
553
558
|
if (status === 'failed') {
|
|
554
559
|
return '<button class="retry-btn" onclick="retryJob(' + "'" + job.id + "'" + ', ' + "'" + (job.queue || currentQueue) + "'" + ')" title="Retry this job">↻ Retry</button>';
|
|
555
560
|
}
|
|
@@ -631,12 +636,21 @@ const getRenderJobsRowHelpersFunction = () => `
|
|
|
631
636
|
tr.className = 'expandable-row';
|
|
632
637
|
tr.addEventListener('click', (e) => {
|
|
633
638
|
if (e.target.classList.contains('retry-btn')) return;
|
|
639
|
+
if (e.target.classList.contains('recover-btn')) return;
|
|
634
640
|
toggleJobDetails(tr, tr.__jobData);
|
|
635
641
|
});
|
|
636
642
|
updateExistingJobRow(tr, job, idx);
|
|
637
643
|
return tr;
|
|
638
644
|
}
|
|
639
645
|
|
|
646
|
+
function formatDateTime(value) {
|
|
647
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
648
|
+
if (Number.isNaN(date.getTime())) {
|
|
649
|
+
return '—';
|
|
650
|
+
}
|
|
651
|
+
return date.toLocaleString();
|
|
652
|
+
}
|
|
653
|
+
|
|
640
654
|
function updateExistingJobRow(tr, job, idx) {
|
|
641
655
|
const jobId = getJobId(job);
|
|
642
656
|
const statusInfo = getJobStatusInfo(job);
|
|
@@ -651,7 +665,7 @@ const getRenderJobsRowHelpersFunction = () => `
|
|
|
651
665
|
'<td>' + (job.queue || currentQueue) + '</td>' +
|
|
652
666
|
'<td><span class="status-badge ' + statusInfo.cls + '">' + statusInfo.label + '</span></td>' +
|
|
653
667
|
'<td>' + job.attempts + '</td>' +
|
|
654
|
-
'<td>' +
|
|
668
|
+
'<td>' + formatDateTime(job.timestamp) + '</td>' +
|
|
655
669
|
'<td>' + getJobRetryMarkup(job) + '</td>';
|
|
656
670
|
|
|
657
671
|
if (job.failedReason) {
|
|
@@ -835,7 +849,7 @@ const getLockHelperFunctions = () => `
|
|
|
835
849
|
|
|
836
850
|
function updateExistingLockRow(row, lock, idx) {
|
|
837
851
|
const ttl = typeof lock.ttl === 'number' ? Math.round(lock.ttl / 1000) + 's' : '—';
|
|
838
|
-
const expires = lock.expires ?
|
|
852
|
+
const expires = lock.expires ? formatDateTime(lock.expires) : '—';
|
|
839
853
|
|
|
840
854
|
const ttlCell = row.children[1];
|
|
841
855
|
const expiresCell = row.children[2];
|
|
@@ -851,7 +865,7 @@ const getLockHelperFunctions = () => `
|
|
|
851
865
|
tr.dataset.lockIndex = idx;
|
|
852
866
|
|
|
853
867
|
const ttl = typeof lock.ttl === 'number' ? Math.round(lock.ttl / 1000) + 's' : '—';
|
|
854
|
-
const expires = lock.expires ?
|
|
868
|
+
const expires = lock.expires ? formatDateTime(lock.expires) : '—';
|
|
855
869
|
const isExpanded = expandedLockKeys.has(lock.key);
|
|
856
870
|
|
|
857
871
|
tr.innerHTML =
|
|
@@ -963,6 +977,36 @@ const getToggleDetailsFunctions = () => `
|
|
|
963
977
|
|
|
964
978
|
row.parentNode.insertBefore(detailRow, row.nextSibling);
|
|
965
979
|
}`;
|
|
980
|
+
const getRecoverActiveJobFunction = () => `
|
|
981
|
+
async function recoverActiveJob(jobId, queueName) {
|
|
982
|
+
try {
|
|
983
|
+
const btn = event.target;
|
|
984
|
+
btn.disabled = true;
|
|
985
|
+
btn.textContent = 'Recovering...';
|
|
986
|
+
|
|
987
|
+
const res = await fetch(API_BASE + '/api/recover-active/' + queueName + '/' + jobId, {
|
|
988
|
+
method: 'POST'
|
|
989
|
+
});
|
|
990
|
+
const payload = await res.json().catch(() => null);
|
|
991
|
+
|
|
992
|
+
if (res.ok) {
|
|
993
|
+
btn.textContent = payload && payload.status === 'removed_after_delayed_retry'
|
|
994
|
+
? 'Removed'
|
|
995
|
+
: 'Recovered';
|
|
996
|
+
setTimeout(() => {
|
|
997
|
+
console.log('HTTP jobs polling disabled - using SSE only');
|
|
998
|
+
}, 1000);
|
|
999
|
+
} else {
|
|
1000
|
+
btn.textContent = 'Failed';
|
|
1001
|
+
btn.disabled = false;
|
|
1002
|
+
}
|
|
1003
|
+
} catch (e) {
|
|
1004
|
+
console.error('Failed to recover active job', e);
|
|
1005
|
+
const btn = event.target;
|
|
1006
|
+
btn.textContent = 'Failed';
|
|
1007
|
+
btn.disabled = false;
|
|
1008
|
+
}
|
|
1009
|
+
}`;
|
|
966
1010
|
const getRetryJobFunction = () => `
|
|
967
1011
|
async function retryJob(jobId, queueName) {
|
|
968
1012
|
try {
|
|
@@ -1133,7 +1177,7 @@ const getDashboardScriptEventStream = () => `
|
|
|
1133
1177
|
|
|
1134
1178
|
const lastUpdated = document.getElementById('last-updated');
|
|
1135
1179
|
if (lastUpdated) {
|
|
1136
|
-
lastUpdated.textContent = new Date()
|
|
1180
|
+
lastUpdated.textContent = formatDateTime(new Date());
|
|
1137
1181
|
}
|
|
1138
1182
|
markStreamHealthy();
|
|
1139
1183
|
}
|
|
@@ -1168,7 +1212,7 @@ const getFetchDataFunction = () => `
|
|
|
1168
1212
|
updateQueueSelect(data.queues);
|
|
1169
1213
|
handleQueueSelection(data);
|
|
1170
1214
|
await fetchLocks();
|
|
1171
|
-
document.getElementById('last-updated').textContent = new Date()
|
|
1215
|
+
document.getElementById('last-updated').textContent = formatDateTime(new Date());
|
|
1172
1216
|
} catch (e) {
|
|
1173
1217
|
showError(e.message);
|
|
1174
1218
|
}
|
|
@@ -1230,6 +1274,7 @@ const getDashboardScriptRender = () => [
|
|
|
1230
1274
|
getLockHelperFunctions(),
|
|
1231
1275
|
getErrorAndTooltipFunctions(),
|
|
1232
1276
|
getToggleDetailsFunctions(),
|
|
1277
|
+
getRecoverActiveJobFunction(),
|
|
1233
1278
|
getRetryJobFunction(),
|
|
1234
1279
|
].join('\n');
|
|
1235
1280
|
const getDashboardScriptBootstrap = () => `
|
package/dist/driver-index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Contains only the core queue driver functionality for production Workers
|
|
4
4
|
*/
|
|
5
5
|
export { createBullMQDriver } from './driver.js';
|
|
6
|
-
export type { JobCounts, JobPayload, QueueDriver, RetryJobResult, RetrySnapshot, } from './driver.js';
|
|
6
|
+
export type { JobCounts, JobPayload, QueueDriver, RecoverActiveJobResult, RetryJobResult, RetrySnapshot, } from './driver.js';
|
package/dist/driver.d.ts
CHANGED
|
@@ -27,6 +27,15 @@ export type RetryJobResult = {
|
|
|
27
27
|
status: 'not_retryable';
|
|
28
28
|
reason?: string;
|
|
29
29
|
};
|
|
30
|
+
export type RecoverActiveJobResult = {
|
|
31
|
+
ok: true;
|
|
32
|
+
status: 'failed' | 'removed' | 'removed_after_delayed_retry' | 'moved';
|
|
33
|
+
state?: string;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
status: 'missing' | 'not_active' | 'not_recoverable';
|
|
37
|
+
reason?: string;
|
|
38
|
+
};
|
|
30
39
|
export type QueueDriver = {
|
|
31
40
|
enqueue<T>(name: string, payload: T, options?: JobsOptions): Promise<string>;
|
|
32
41
|
getJob(queueName: string, jobId: string): Promise<Job | undefined>;
|
|
@@ -37,6 +46,7 @@ export type QueueDriver = {
|
|
|
37
46
|
}>>;
|
|
38
47
|
getRecentJobs(queueName: string, limit?: number): Promise<Job[]>;
|
|
39
48
|
retryJob(queueName: string, jobId: string, snapshot?: RetrySnapshot): Promise<RetryJobResult>;
|
|
49
|
+
recoverActiveJob(queueName: string, jobId: string): Promise<RecoverActiveJobResult>;
|
|
40
50
|
getQueues(): Promise<string[]>;
|
|
41
51
|
close(): Promise<void>;
|
|
42
52
|
};
|
package/dist/driver.js
CHANGED
|
@@ -123,6 +123,73 @@ const createRedisRpcRetryJob = async (queueName, jobId) => {
|
|
|
123
123
|
const client = await createRpcClient();
|
|
124
124
|
return client.queue('retryJob', { target: queueName, args: [jobId] });
|
|
125
125
|
};
|
|
126
|
+
const redisRpcRecoverActiveLockMs = () => Math.max(1, Env.getInt('QUEUE_MONITOR_RECOVER_ACTIVE_LOCK_MS', 30_000));
|
|
127
|
+
const redisRpcBullMqPrefix = () => Env.get('REDIS_RPC_BULLMQ_PREFIX', Env.get('BULLMQ_PREFIX', 'bull')).replace(/:+$/u, '');
|
|
128
|
+
const inspectRecoveredRedisRpcJob = async (client, queueName, jobId) => {
|
|
129
|
+
const job = await client.queue('getJob', {
|
|
130
|
+
target: queueName,
|
|
131
|
+
args: [jobId],
|
|
132
|
+
});
|
|
133
|
+
if (!job)
|
|
134
|
+
return { ok: true, status: 'removed' };
|
|
135
|
+
if (job.state === 'failed')
|
|
136
|
+
return { ok: true, status: 'failed', state: job.state };
|
|
137
|
+
if (job.state === 'delayed') {
|
|
138
|
+
await client.queue('removeJob', { target: queueName, args: [jobId] });
|
|
139
|
+
return { ok: true, status: 'removed_after_delayed_retry', state: job.state };
|
|
140
|
+
}
|
|
141
|
+
if (job.state && job.state !== 'active') {
|
|
142
|
+
return { ok: true, status: 'moved', state: job.state };
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
ok: false,
|
|
146
|
+
status: 'not_recoverable',
|
|
147
|
+
reason: `Job is ${job.state ?? 'unknown'} after recovery attempt`,
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
const createRedisRpcRecoverActiveJob = async (queueName, jobId) => {
|
|
151
|
+
const client = await createRpcClient();
|
|
152
|
+
const existingJob = await client.queue('getJob', {
|
|
153
|
+
target: queueName,
|
|
154
|
+
args: [jobId],
|
|
155
|
+
});
|
|
156
|
+
if (!existingJob)
|
|
157
|
+
return { ok: false, status: 'missing' };
|
|
158
|
+
if (existingJob.state !== 'active') {
|
|
159
|
+
return {
|
|
160
|
+
ok: false,
|
|
161
|
+
status: 'not_active',
|
|
162
|
+
reason: `Job is ${existingJob.state ?? 'unknown'}, not active`,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const visibilityTimeoutMs = redisRpcRecoverActiveLockMs();
|
|
166
|
+
try {
|
|
167
|
+
await client.queue('fail', {
|
|
168
|
+
target: queueName,
|
|
169
|
+
args: [jobId, 'manual queue-monitor stale active recovery'],
|
|
170
|
+
force: true,
|
|
171
|
+
discard: true,
|
|
172
|
+
visibilityTimeoutMs,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
const prefix = redisRpcBullMqPrefix();
|
|
177
|
+
await callRedisRpc('redis', 'call', {
|
|
178
|
+
args: [
|
|
179
|
+
'set',
|
|
180
|
+
`${prefix}:${queueName}:${jobId}:lock`,
|
|
181
|
+
'pull-worker',
|
|
182
|
+
'PX',
|
|
183
|
+
String(visibilityTimeoutMs),
|
|
184
|
+
],
|
|
185
|
+
});
|
|
186
|
+
await client.queue('fail', {
|
|
187
|
+
target: queueName,
|
|
188
|
+
args: [jobId, 'manual queue-monitor stale active recovery'],
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return inspectRecoveredRedisRpcJob(client, queueName, jobId);
|
|
192
|
+
};
|
|
126
193
|
const createRedisRpcGetQueues = async () => {
|
|
127
194
|
const client = await createRpcClient();
|
|
128
195
|
try {
|
|
@@ -144,6 +211,7 @@ const createRedisRpcDriver = () => Object.freeze({
|
|
|
144
211
|
getJobCountsMany: createRedisRpcGetJobCountsMany,
|
|
145
212
|
getRecentJobs: createRedisRpcRecentJobs,
|
|
146
213
|
retryJob: createRedisRpcRetryJob,
|
|
214
|
+
recoverActiveJob: createRedisRpcRecoverActiveJob,
|
|
147
215
|
getQueues: createRedisRpcGetQueues,
|
|
148
216
|
close: createRedisRpcClose,
|
|
149
217
|
});
|
|
@@ -190,9 +258,9 @@ async function discoverQueuesFromRedis(redis, inMemoryQueues) {
|
|
|
190
258
|
const createBullMQQueueGetter = (queues, redis) => {
|
|
191
259
|
return async (name) => {
|
|
192
260
|
if (!queues.has(name)) {
|
|
193
|
-
const
|
|
261
|
+
const QueueConstructor = await ensureBullmqLoaded();
|
|
194
262
|
const prefix = getBullMQSafeQueueName();
|
|
195
|
-
const queue = new
|
|
263
|
+
const queue = new QueueConstructor(name, { prefix, connection: redis });
|
|
196
264
|
queues.set(name, queue);
|
|
197
265
|
}
|
|
198
266
|
const queue = queues.get(name);
|
|
@@ -294,6 +362,34 @@ const createBullMQRetryJob = (getQueue, getJob) => async (queueName, jobId, snap
|
|
|
294
362
|
};
|
|
295
363
|
}
|
|
296
364
|
};
|
|
365
|
+
const createBullMQRecoverActiveJob = (getQueue, getJob) => async (queueName, jobId) => {
|
|
366
|
+
const queue = await getQueue(queueName);
|
|
367
|
+
const job = await getJob(queueName, jobId);
|
|
368
|
+
if (!job)
|
|
369
|
+
return { ok: false, status: 'missing' };
|
|
370
|
+
const state = await job.getState().catch(() => undefined);
|
|
371
|
+
if (state !== 'active') {
|
|
372
|
+
return {
|
|
373
|
+
ok: false,
|
|
374
|
+
status: 'not_active',
|
|
375
|
+
reason: `Job is ${state ?? 'unknown'}, not active`,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
try {
|
|
379
|
+
job.discard();
|
|
380
|
+
const client = await queue.client;
|
|
381
|
+
await client.set(queue.toKey(jobId) + ':lock', 'pull-worker', 'PX', String(Math.max(1, Env.getInt('QUEUE_MONITOR_RECOVER_ACTIVE_LOCK_MS', 30_000))));
|
|
382
|
+
await job.moveToFailed(new Error('manual queue-monitor stale active recovery'), 'pull-worker', false);
|
|
383
|
+
return { ok: true, status: 'failed' };
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
return {
|
|
387
|
+
ok: false,
|
|
388
|
+
status: 'not_recoverable',
|
|
389
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
};
|
|
297
393
|
const createBullMQGetRecentJobs = (getQueue) => async (queueName, limit = 100) => {
|
|
298
394
|
const queue = await getQueue(queueName);
|
|
299
395
|
const jobs = await queue.getJobs(['completed', 'failed', 'active', 'waiting', 'delayed', 'paused'], 0, Math.max(0, limit - 1), true);
|
|
@@ -320,6 +416,7 @@ export const createBullMQDriver = (config) => {
|
|
|
320
416
|
getJobCountsMany: createBullMQGetJobCountsMany(createBullMQGetJobCounts(getQueue)),
|
|
321
417
|
getRecentJobs: createBullMQGetRecentJobs(getQueue),
|
|
322
418
|
retryJob: createBullMQRetryJob(getQueue, createBullMQGetJob(getQueue)),
|
|
419
|
+
recoverActiveJob: createBullMQRecoverActiveJob(getQueue, createBullMQGetJob(getQueue)),
|
|
323
420
|
getQueues: createBullMQGetQueues(redis, queues),
|
|
324
421
|
close: createBullMQClose(queues),
|
|
325
422
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type QueueDriver } from './driver.js';
|
|
|
4
4
|
import { type Metrics } from './metrics.js';
|
|
5
5
|
export { getRecentJobsForQueue, getRecentJobsForSelection, QueueMonitoringService, QueueMonitoringStream, } from './QueueMonitoringService.js';
|
|
6
6
|
export { createBullMQDriver } from './driver.js';
|
|
7
|
-
export type { JobPayload, QueueDriver } from './driver.js';
|
|
7
|
+
export type { JobPayload, QueueDriver, RecoverActiveJobResult } from './driver.js';
|
|
8
8
|
export { createMetrics, type JobStatus, type JobSummary, type Metrics } from './metrics.js';
|
|
9
9
|
export { createWorker as createQueueWorker, type QueueWorker } from './worker.js';
|
|
10
10
|
export type QueueMonitorConfig = {
|
package/dist/index.js
CHANGED
|
@@ -227,6 +227,27 @@ async function handleRetryEndpoint(req, res, driver, metrics) {
|
|
|
227
227
|
status: result.status,
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
|
+
async function handleRecoverActiveEndpoint(req, res, driver) {
|
|
231
|
+
const queueName = extractQueueParam(req);
|
|
232
|
+
const jobId = typeof req.getParam === 'function' ? req.getParam?.('jobId') : req.params?.['jobId'];
|
|
233
|
+
if (!queueName || !jobId) {
|
|
234
|
+
res.status(400).json(fieldError('queue_name,job_id', 'Queue name and job ID must be provided'));
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const result = await driver.recoverActiveJob(queueName, jobId);
|
|
238
|
+
if (result.ok) {
|
|
239
|
+
res.json({ ok: true, status: result.status, state: result.state });
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (result.status === 'missing') {
|
|
243
|
+
res.status(404).json({ error: `Job ${jobId} no longer exists`, status: result.status });
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
res.status(409).json({
|
|
247
|
+
error: result.reason ?? `Job ${jobId} cannot be recovered in its current state`,
|
|
248
|
+
status: result.status,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
230
251
|
function buildSettings(config) {
|
|
231
252
|
return {
|
|
232
253
|
enabled: config.enabled ?? DEFAULTS.enabled,
|
|
@@ -325,6 +346,7 @@ function registerApiRoutes(router, settings, routeOptions, metrics, driver, getS
|
|
|
325
346
|
registerJobsApi(router, settings, routeOptions, metrics, driver);
|
|
326
347
|
registerLocksApi(router, settings, routeOptions, getLocks);
|
|
327
348
|
registerRetryApi(router, settings, routeOptions, driver, metrics);
|
|
349
|
+
registerRecoverActiveApi(router, settings, routeOptions, driver);
|
|
328
350
|
registerEventsApi(router, settings, routeOptions, getSnapshot, getLocks, metrics, driver);
|
|
329
351
|
}
|
|
330
352
|
function registerSnapshotApi(router, settings, routeOptions, getSnapshot) {
|
|
@@ -353,6 +375,11 @@ function registerRetryApi(router, settings, routeOptions, driver, metrics) {
|
|
|
353
375
|
await handleRetryEndpoint(req, res, driver, metrics);
|
|
354
376
|
}, routeOptions);
|
|
355
377
|
}
|
|
378
|
+
function registerRecoverActiveApi(router, settings, routeOptions, driver) {
|
|
379
|
+
Router.post(router, `${settings.basePath}/api/recover-active/:queue/:jobId`, async (req, res) => {
|
|
380
|
+
await handleRecoverActiveEndpoint(req, res, driver);
|
|
381
|
+
}, routeOptions);
|
|
382
|
+
}
|
|
356
383
|
function registerEventsApi(router, settings, routeOptions, getSnapshot, getLocks, metrics, driver) {
|
|
357
384
|
Router.get(router, `${settings.basePath}/api/events`, async (req, res) => {
|
|
358
385
|
QueueMonitoringStream(res, req, getSnapshot, getLocks, metrics, driver, settings);
|