-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
45 lines (39 loc) · 1.57 KB
/
app.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
const createRequests = require('./requests').createRequests
const updateChainlinkGasPrice = require('./chainlink').updateChainlinkGasPrice
const authenticate = require('./chainlink').authenticate
const extrapolate = require('./extrapolator').extrapolate
const logger = require('./logger').logger
const config = require('./config').config
const express = require('express')
const bodyParser = require('body-parser')
const cron = require('node-cron')
const app = express()
app.use(bodyParser.json())
app.get('/health', (req, res) => {
res.status(200).send('ok')
})
cron.schedule(config.schedule, async () => {
// Special case for authenticate since it will always fail on standby nodes
try {
const cookie = await authenticate(config.chainlink)
try {
const currentGasPrice = await createRequests(config.details)
logger.debug('Current gas price: ' + currentGasPrice.toString())
const extrapolatedGasPrice = extrapolate(config.details, currentGasPrice)
logger.debug('Extrapolated gas price: ' + extrapolatedGasPrice.toString())
const gasPrice = Math.max(currentGasPrice, extrapolatedGasPrice)
await updateChainlinkGasPrice(config.chainlink.url, cookie, gasPrice)
logger.info('Gas price updated: ' + gasPrice.toString())
} catch (error) {
logger.error(error)
}
} catch (error) {
// This keeps the log quiet for standby nodes unless set to debug
logger.debug(error)
}
})
app.listen(config.port, () => logger.info(`Listening on port ${config.port}!`))
process.on('SIGINT', () => {
logger.info('Shutting down')
process.exit()
})