2020-06-10 16:22:01 +03:00
|
|
|
require('dotenv').config()
|
2019-05-08 16:12:02 +03:00
|
|
|
const logger = require('./logger')('checkWorker2')
|
|
|
|
const eventsStats = require('./eventsStats')
|
2021-04-02 12:59:49 +03:00
|
|
|
const getEventsInfo = require('./utils/events')
|
2019-05-08 16:12:02 +03:00
|
|
|
const alerts = require('./alerts')
|
2020-01-10 15:55:35 +03:00
|
|
|
const { writeFile, createDir } = require('./utils/file')
|
2020-10-29 11:25:43 +03:00
|
|
|
const { saveCache } = require('./utils/web3Cache')
|
2020-01-10 15:55:35 +03:00
|
|
|
|
|
|
|
const { MONITOR_BRIDGE_NAME } = process.env
|
2019-05-08 16:12:02 +03:00
|
|
|
|
|
|
|
async function checkWorker2() {
|
|
|
|
try {
|
2020-01-10 15:55:35 +03:00
|
|
|
createDir(`/responses/${MONITOR_BRIDGE_NAME}`)
|
2021-04-02 12:59:49 +03:00
|
|
|
logger.debug('calling getEventsInfo()')
|
|
|
|
const eventsInfo = await getEventsInfo()
|
2019-05-08 16:12:02 +03:00
|
|
|
logger.debug('calling eventsStats()')
|
2021-04-02 12:59:49 +03:00
|
|
|
const evStats = await eventsStats(eventsInfo)
|
2019-05-08 16:12:02 +03:00
|
|
|
if (!evStats) throw new Error('evStats is empty: ' + JSON.stringify(evStats))
|
2020-01-10 15:55:35 +03:00
|
|
|
evStats.ok =
|
|
|
|
(evStats.onlyInHomeDeposits || evStats.home.deliveredMsgNotProcessedInForeign).length === 0 &&
|
|
|
|
(evStats.onlyInForeignDeposits || evStats.home.processedMsgNotDeliveredInForeign).length === 0 &&
|
|
|
|
(evStats.onlyInHomeWithdrawals || evStats.foreign.deliveredMsgNotProcessedInHome).length === 0 &&
|
|
|
|
(evStats.onlyInForeignWithdrawals || evStats.foreign.processedMsgNotDeliveredInHome).length === 0
|
2020-05-18 21:24:16 +03:00
|
|
|
evStats.health = true
|
2020-01-10 15:55:35 +03:00
|
|
|
writeFile(`/responses/${MONITOR_BRIDGE_NAME}/eventsStats.json`, evStats)
|
|
|
|
|
2019-05-08 16:12:02 +03:00
|
|
|
logger.debug('calling alerts()')
|
2021-04-02 12:59:49 +03:00
|
|
|
const _alerts = await alerts(eventsInfo)
|
2019-05-08 16:12:02 +03:00
|
|
|
if (!_alerts) throw new Error('alerts is empty: ' + JSON.stringify(_alerts))
|
2020-01-10 15:55:35 +03:00
|
|
|
_alerts.ok = !_alerts.executeAffirmations.mostRecentTxHash && !_alerts.executeSignatures.mostRecentTxHash
|
2020-05-18 21:24:16 +03:00
|
|
|
_alerts.health = true
|
2020-01-10 15:55:35 +03:00
|
|
|
writeFile(`/responses/${MONITOR_BRIDGE_NAME}/alerts.json`, _alerts)
|
2020-10-29 11:25:43 +03:00
|
|
|
saveCache()
|
2019-05-08 16:12:02 +03:00
|
|
|
logger.debug('Done x2')
|
|
|
|
} catch (e) {
|
2019-05-30 21:05:36 +03:00
|
|
|
logger.error(e)
|
2019-05-08 16:12:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
checkWorker2()
|