Skip to content

Commit ed6d49e

Browse files
committed
Update cronJobs.ts
1 parent 012f183 commit ed6d49e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/utils/cronJobs.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,17 @@ export async function incrementEloCronJobAllQueues() {
161161
const matchupUsers = bestPair.map((u) => u.userId)
162162

163163
// remove users from all queues they are in
164-
for (const userId of matchupUsers) {
165-
const userQueues = await getUserQueues(userId)
166-
for (const queue of userQueues) {
167-
await removeUserFromQueue(queue.id, userId)
168-
}
169-
}
164+
// Wait for all removal operations to complete before creating match
165+
await Promise.all(
166+
matchupUsers.map(async (userId) => {
167+
const userQueues = await getUserQueues(userId)
168+
await Promise.all(
169+
userQueues.map((queue) =>
170+
removeUserFromQueue(queue.id, userId),
171+
),
172+
)
173+
}),
174+
)
170175

171176
// queue them for the match
172177
await createMatch(matchupUsers, bestPair[0].queueId)

0 commit comments

Comments
 (0)