Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(queue): clean works iteratively #2260

Merged
merged 2 commits into from
Nov 5, 2023
Merged
Changes from 1 commit
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
28 changes: 21 additions & 7 deletions src/classes/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,28 @@ export class Queue<
| 'delayed'
| 'failed' = 'completed',
): Promise<string[]> {
const jobs = await this.scripts.cleanJobsInSet(
type,
Date.now() - grace,
limit,
);
limit = limit || Infinity;
manast marked this conversation as resolved.
Show resolved Hide resolved
const maxCountPerCall = Math.min(10000, limit);
const timestamp = Date.now() - grace;
let deletedCount = 0;
const deletedJobsIds: string[] = [];

while (deletedCount < limit) {
const jobsIds = await this.scripts.cleanJobsInSet(
type,
timestamp,
maxCountPerCall,
);

this.emit('cleaned', jobsIds, type);
deletedCount += jobsIds.length;
deletedJobsIds.push(...jobsIds);

this.emit('cleaned', jobs, type);
return jobs;
if (jobsIds.length < maxCountPerCall) {
break;
}
}
return deletedJobsIds;
}

/**
Expand Down