optimize, wait between async calls, auto repeat

master
lza_menace 3 weeks ago
parent cce9009e04
commit 487701145a

@ -124,7 +124,8 @@ class Scrape extends Collection {
// get transfer events from a batch from filtering // get transfer events from a batch from filtering
async getTransferEvents(txEvents) { async getTransferEvents(txEvents) {
txEvents.forEach(async tx => { for (const tx of txEvents) {
await sleep(1);
let tokenId; let tokenId;
if (this.erc1155) { if (this.erc1155) {
tokenId = tx.args.id.toString(); tokenId = tx.args.id.toString();
@ -153,7 +154,7 @@ class Scrape extends Collection {
writeToDatabase(q) writeToDatabase(q)
// .then((_) => this.writeLastBlock(tx.blockNumber)) // .then((_) => this.writeLastBlock(tx.blockNumber))
.catch((err) => console.log(`Error writing to database: ${err}`)); .catch((err) => console.log(`Error writing to database: ${err}`));
}); };
} }
// get sales events from a given transaction // get sales events from a given transaction
@ -450,8 +451,13 @@ async function writeToDatabase(_q) {
for(const key in ALL_CONTRACTS) { for(const key in ALL_CONTRACTS) {
if (process.env.ONLY && process.env.ONLY != key) continue if (process.env.ONLY && process.env.ONLY != key) continue
const c = new Scrape(key, latestBlock); const c = new Scrape(key, latestBlock);
c.scrape(); try {
await sleep(2); await c.scrape();
await sleep(2);
} catch(e) {
console.log(e);
await sleep(10);
}
} }
} }
} }

Loading…
Cancel
Save