-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.js
31 lines (24 loc) · 1.2 KB
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import dotenv from "dotenv"
dotenv.config()
import mongoose from "mongoose";
await mongoose.connect(process.env.MONGO_URI).catch((err) => console.error(err));
console.log('Connected to MongoDB!')
import {RedisConnection} from "./db/redis.js";
let redisClient = await RedisConnection.getClient();
import {indexForward} from "./indexer/indexForward.js";
import {indexBackward} from "./indexer/indexBackward.js";
import {indexOlderTransactions} from "./indexer/indexOlderTransactions.js"
import {ChainConfig} from "./config/chainConfig.js";
let indexingInterval = 5000; // ideally 15 seconds
// Schedule indexing for all chains inside ChainConfig
for (let key of Object.keys(ChainConfig)) {
// Reset indexing status
await redisClient.set(`${ChainConfig[key].name}_IS_INDEXING_FORWARD`, "false")
await redisClient.set(`${ChainConfig[key].name}_IS_INDEXING_BACKWARD`, "false")
setInterval(indexForward, indexingInterval, ChainConfig[key])
setInterval(indexBackward, indexingInterval, ChainConfig[key])
// Index older transactions
if (ChainConfig[key].oldestBlock) {
indexOlderTransactions(ChainConfig[key]).then(() => console.log(`Finished backindexing ${ChainConfig[key].name}`))
}
}