Skip to content

Commit

Permalink
add timeout when collection auctions
Browse files Browse the repository at this point in the history
  • Loading branch information
xtatanx committed Jun 8, 2023
1 parent db0107c commit 6a0bd43
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ export async function collectAuctions() {
.innerText();

const total = parseInt(totalResultsText.split(' ')[0]);
console.log('::: Total results :::');
console.log(total);

const auctionIds = [];
const LIMIT = 120000;
const now = Date.now();
let shouldCollect = true;

while (shouldCollect) {
Expand Down Expand Up @@ -81,6 +85,10 @@ export async function collectAuctions() {
if (auctionIds.length === total) {
shouldCollect = false;
}

if (Math.floor((Date.now() - now) / 1000) > LIMIT) {
throw new Error('Timeout to collect auctions');
}
}

await context.close();
Expand Down

0 comments on commit 6a0bd43

Please sign in to comment.