@zintrust/redis-rpc 2.4.8 → 2.4.9
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/README.md +3 -1
- package/dist/backend.js +16 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -206,7 +206,9 @@ Queue requests identify the queue with `payload.target`, `payload.queueName`, or
|
|
|
206
206
|
|
|
207
207
|
`dequeue` is for pull-based runtimes. It uses BullMQ's own atomic waiting-to-active transition and returns `{ id, name, payload, attempts }`. The caller must report the result with `ack` or `fail` / `nack`. `ack` accepts an optional return value as `payload.returnValue`, `payload.returnvalue`, or the second positional arg. `fail` / `nack` accepts an optional failure reason as `payload.reason` or the second positional arg.
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
As of `@zintrust/redis-rpc@2.4.8`, `dequeue` also scans up to 100 active jobs for the queue and recovers stale pull-worker jobs whose `processedOn` age exceeds `REDIS_RPC_STALE_ACTIVE_MS`. When the variable is unset, the backend uses `max(visibilityTimeoutMs * 2, 120000)`. Recovered jobs are marked failed and their pull-claim keys are released so normal replay policy can handle follow-up processing.
|
|
210
|
+
|
|
211
|
+
The local source also discards recovered stale jobs before `moveToFailed(...)` so they become terminal failures instead of delayed retries when attempts remain. Queue-monitor snapshot and recent-job reads run the same recovery pass, which keeps stale active jobs from lingering when no pull worker is polling. Manual recovery can use `queue.fail` with `force: true` or `discard: true` to recreate the pull-worker lock, discard retries, and fail the job.
|
|
210
212
|
|
|
211
213
|
### `worker`
|
|
212
214
|
|
package/dist/backend.js
CHANGED
|
@@ -268,6 +268,10 @@ const releaseClaim = async (state, queueName, jobId) => {
|
|
|
268
268
|
connection.disconnect();
|
|
269
269
|
}
|
|
270
270
|
};
|
|
271
|
+
const ensurePullWorkerJobLock = async (queue, jobId, ttlMs) => {
|
|
272
|
+
const client = await queue.client;
|
|
273
|
+
await client.set(queue.toKey(jobId) + ':lock', PULL_WORKER_TOKEN, 'PX', Math.max(1, ttlMs));
|
|
274
|
+
};
|
|
271
275
|
const staleActiveThresholdMs = (visibilityTimeoutMs) => {
|
|
272
276
|
const override = positiveNumberFrom(process.env['REDIS_RPC_STALE_ACTIVE_MS']);
|
|
273
277
|
if (override !== null) {
|
|
@@ -278,7 +282,6 @@ const staleActiveThresholdMs = (visibilityTimeoutMs) => {
|
|
|
278
282
|
const recoverStaleActiveJobs = async (state, queueName, queue, visibilityTimeoutMs) => {
|
|
279
283
|
const thresholdMs = staleActiveThresholdMs(visibilityTimeoutMs);
|
|
280
284
|
const activeJobs = await queue.getJobs(['active'], 0, 99, true);
|
|
281
|
-
const client = await queue.client;
|
|
282
285
|
for (const job of activeJobs) {
|
|
283
286
|
if (isUndefinedOrNull(job.processedOn) || isUndefinedOrNull(job.id)) {
|
|
284
287
|
continue;
|
|
@@ -293,8 +296,9 @@ const recoverStaleActiveJobs = async (state, queueName, queue, visibilityTimeout
|
|
|
293
296
|
}
|
|
294
297
|
const jobId = String(job.id);
|
|
295
298
|
try {
|
|
299
|
+
job.discard();
|
|
296
300
|
// eslint-disable-next-line no-await-in-loop
|
|
297
|
-
await
|
|
301
|
+
await ensurePullWorkerJobLock(queue, jobId, visibilityTimeoutMs);
|
|
298
302
|
// eslint-disable-next-line no-await-in-loop
|
|
299
303
|
await job.moveToFailed(new Error(`stale active job recovered after ${ageMs}ms without ack/fail`), PULL_WORKER_TOKEN, false);
|
|
300
304
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -353,6 +357,12 @@ const failQueueJob = async (state, queueName, payload) => {
|
|
|
353
357
|
const reason = isNonEmptyString(firstDefined(args[1], payload.reason))
|
|
354
358
|
? String(firstDefined(args[1], payload.reason))
|
|
355
359
|
: 'failed by pull worker';
|
|
360
|
+
if (boolFrom(payload.force, false) || boolFrom(payload.discard, false)) {
|
|
361
|
+
if (!isUndefinedOrNull(job.id)) {
|
|
362
|
+
await ensurePullWorkerJobLock(getQueue(state, queueName), String(job.id), Math.max(1, numberFrom(payload.visibilityTimeoutMs, 30_000)));
|
|
363
|
+
}
|
|
364
|
+
job.discard();
|
|
365
|
+
}
|
|
356
366
|
await job.moveToFailed(new Error(reason), PULL_WORKER_TOKEN, false);
|
|
357
367
|
if (!isUndefinedOrNull(job.id)) {
|
|
358
368
|
await releaseClaim(state, queueName, String(job.id));
|
|
@@ -598,7 +608,9 @@ const dispatchMonitor = async (state, method, payload) => {
|
|
|
598
608
|
}
|
|
599
609
|
const queues = await Promise.all(queueNames.map(async (name) => {
|
|
600
610
|
const queueName = requireString(name, 'queueName');
|
|
601
|
-
|
|
611
|
+
const queue = getQueue(state, queueName);
|
|
612
|
+
await recoverStaleActiveJobs(state, queueName, queue, numberFrom(payload.visibilityTimeoutMs, 30_000));
|
|
613
|
+
return { name: queueName, counts: await queue.getJobCounts() };
|
|
602
614
|
}));
|
|
603
615
|
return { status: 'ok', startedAt: new Date().toISOString(), queues };
|
|
604
616
|
}
|
|
@@ -610,6 +622,7 @@ const dispatchMonitor = async (state, method, payload) => {
|
|
|
610
622
|
}
|
|
611
623
|
case 'getRecentJobsForQueue': {
|
|
612
624
|
const queueName = requireString(firstDefined(args[0], payload.queueName, payload.queue), 'queueName');
|
|
625
|
+
await recoverStaleActiveJobs(state, queueName, getQueue(state, queueName), numberFrom(payload.visibilityTimeoutMs, 30_000));
|
|
613
626
|
return dispatchQueue(state, 'getJobs', {
|
|
614
627
|
...payload,
|
|
615
628
|
args: [],
|