-
Notifications
You must be signed in to change notification settings - Fork 22
/
validatorWorker.js
74 lines (63 loc) · 2.61 KB
/
validatorWorker.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Bugsnag from "@bugsnag/js"
import ChainRegistry from './chains/chainRegistry.js';
import ValidatorMonitor from './validators/validatorMonitor.js';
import { redisClient } from "./redisClient.js";
import ValidatorImageMonitor from "./validators/validatorImageMonitor.js";
import ServicesMonitor from "./services/servicesMonitor.js";
const validatorRefreshSeconds = parseInt(process.env.VALIDATOR_REFRESH || 60 * 5)
const validatorImageRefreshSeconds = parseInt(process.env.VALIDATOR_IMAGE_REFRESH || 60 * 60 * 12)
const servicesRefreshSeconds = parseInt(process.env.STAKING_REWARDS_REFRESH || 60 * 60)
const stakingRewardsKey = process.env.STAKING_REWARDS_KEY
console.log("Using config:", {
validatorRefreshSeconds,
validatorImageRefreshSeconds,
servicesRefreshSeconds
})
if(process.env.BUGSNAG_KEY){
Bugsnag.start({
apiKey: process.env.BUGSNAG_KEY,
enabledReleaseStages: ['production', 'staging'],
releaseStage: process.env.NODE_ENV
})
}
async function queueValidatorCheck(client, registry, monitor) {
setTimeout(async () => {
const chains = await registry.getChains()
await monitor.refreshValidators(client, chains)
queueValidatorCheck(client, registry, monitor)
}, 1000 * validatorRefreshSeconds)
}
async function queueValidatorImageCheck(client, registry, monitor) {
setTimeout(async () => {
const chains = await registry.getChains()
await monitor.refreshValidatorImages(client, chains)
queueValidatorImageCheck(client, registry, monitor)
}, 1000 * validatorImageRefreshSeconds)
}
async function queueServicesCheck(client, registry, monitor) {
setTimeout(async () => {
const chains = await registry.getChains()
await monitor.refreshServices(client, chains, stakingRewardsKey)
queueServicesCheck(client, registry, monitor)
}, 1000 * servicesRefreshSeconds)
}
(async () => {
const client = await redisClient();
const chainRegistry = ChainRegistry(client)
const chains = await chainRegistry.getChains()
const validatorMonitor = ValidatorMonitor()
await validatorMonitor.refreshValidators(client, chains)
if (validatorRefreshSeconds > 0) {
queueValidatorCheck(client, chainRegistry, validatorMonitor)
}
const validatorImageMonitor = ValidatorImageMonitor()
validatorImageMonitor.refreshValidatorImages(client, chains)
if (validatorImageRefreshSeconds > 0) {
queueValidatorImageCheck(client, chainRegistry, validatorImageMonitor)
}
const servicesMonitor = ServicesMonitor()
servicesMonitor.refreshServices(client, chains, stakingRewardsKey)
if (servicesRefreshSeconds > 0) {
queueServicesCheck(client, chainRegistry, servicesMonitor)
}
})();