From 487701145ad1aa2700a7fb3a9ec537ca717860fb Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sat, 21 Dec 2024 16:56:15 -0800 Subject: [PATCH] optimize, wait between async calls, auto repeat --- src/scraper.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/scraper.js b/src/scraper.js index 8e6b6c0..99ebaba 100644 --- a/src/scraper.js +++ b/src/scraper.js @@ -124,7 +124,8 @@ class Scrape extends Collection { // get transfer events from a batch from filtering async getTransferEvents(txEvents) { - txEvents.forEach(async tx => { + for (const tx of txEvents) { + await sleep(1); let tokenId; if (this.erc1155) { tokenId = tx.args.id.toString(); @@ -153,7 +154,7 @@ class Scrape extends Collection { writeToDatabase(q) // .then((_) => this.writeLastBlock(tx.blockNumber)) .catch((err) => console.log(`Error writing to database: ${err}`)); - }); + }; } // get sales events from a given transaction @@ -450,8 +451,13 @@ async function writeToDatabase(_q) { for(const key in ALL_CONTRACTS) { if (process.env.ONLY && process.env.ONLY != key) continue const c = new Scrape(key, latestBlock); - c.scrape(); - await sleep(2); + try { + await c.scrape(); + await sleep(2); + } catch(e) { + console.log(e); + await sleep(10); + } } } }