Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/queue/managedQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,31 @@ export class ManagedQueue<T = unknown, R = unknown> implements ManagedQueuePort<
return false;
}

// If the job is in the DLQ (failed state from stall/max-attempts), removeAsync
// cannot handle it. Pause the queue to prevent the worker from picking up the
// job, retry it (moves from DLQ to waiting), then remove and resume.
if (stateBefore === "failed") {
this.queue.pause();
try {
await this.queue.retryJob(jobId);
await this.queue.removeAsync(jobId);
} finally {
this.queue.resume();
}
const stateAfter = await this.queue.getJobState(jobId);
if (stateAfter === "unknown") {
logger.info(`Removed DLQ job ${jobId} from "${this.queue.name}"`);
try {
getLogStore().deleteMany([jobId]);
} catch {
logger.warn(`Failed to clean persisted logs for DLQ job ${jobId}`);
}
return true;
}
logger.warn(`Job ${jobId} still present after retry+remove in "${this.queue.name}" (state: ${stateAfter})`);
return false;
}

// removeAsync handles queue, waitingDeps, and waitingChildren states.
await this.queue.removeAsync(jobId);

Expand Down
15 changes: 12 additions & 3 deletions src/web/jobCanceller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ export class JobCanceller {
if (chainResult) {
jobsToDelete = chainResult.siblings.map((job) => ({ id: job.id, queueName: job.queue }));
} else {
jobsToDelete = [{ id: jobId, queueName: "" }];
// Not part of a chain — use the cached entry's queue name for targeted removal.
const cachedEntry = this.deps.getCachedJob(jobId);
const queueName = cachedEntry?.queue ?? "";
jobsToDelete = [{ id: jobId, queueName }];
}

let overallStatus = true;
Expand All @@ -151,14 +154,20 @@ export class JobCanceller {
if (removed) {
this.deps.evictJob(jobToDelete.id);
this.markCancelled(jobToDelete.id);
} else if (job.state === "failed" || job.state === "completed") {
// Job is in a terminal state (e.g. DLQ) that cancelJob can't remove.
// Evict from cache so it doesn't linger as a stale entry.
this.deps.evictJob(jobToDelete.id);
} else {
overallStatus = false;
}
} else {
overallStatus = false;
// Job no longer exists in the queue — evict the stale cache entry.
this.deps.evictJob(jobToDelete.id);
}
} else {
overallStatus = false;
// Queue not found — evict the orphaned cache entry.
this.deps.evictJob(jobToDelete.id);
}
}

Expand Down
Loading
Loading