Skip to content

Commit f09768d

Browse files
committed
add code for emptying queue
1 parent f49b217 commit f09768d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/api/scheduler/jobs-repo.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,23 @@ export class JobsRepo implements Closable {
145145
);
146146
}
147147

148+
public async emptyQueue(tokenId: string, endpoint: string) {
149+
let cursor = 0;
150+
const allPromises: Promise<any>[] = [];
151+
do {
152+
const { cursor: newCursor, jobs } = await this.find(tokenId, endpoint, {
153+
cursor,
154+
});
155+
cursor = newCursor;
156+
157+
for (const job of jobs) {
158+
allPromises.push(this.delete(tokenId, endpoint, job.id));
159+
}
160+
} while (cursor !== 0);
161+
162+
await Promise.all(allPromises);
163+
}
164+
148165
public async delete(tokenId: string, endpoint: string, id: string) {
149166
return await this.producer.delete(
150167
encodeQueueDescriptor(tokenId, endpoint),

0 commit comments

Comments
 (0)