[state]: watchers return a state
This commit is contained in:
@@ -2,15 +2,17 @@ import {watcherLoop} from "../../watcherLoop";
|
||||
import {Conf, ConfURL} from "../../types/conf";
|
||||
import Axios from "axios";
|
||||
import {mail} from "../../mail";
|
||||
import {Watcher} from "../../types/state";
|
||||
|
||||
export function urlWatcher(conf: Conf, checkValidity: (data: any) => Promise<void>) {
|
||||
|
||||
return async (urlConf: ConfURL) => {
|
||||
return async (urlConf: ConfURL): Promise<Watcher> => {
|
||||
|
||||
let nodeDownRes: () => void
|
||||
let nodeDownPromise: Promise<void> = new Promise(res => nodeDownRes = res)
|
||||
|
||||
await watcherLoop(
|
||||
return watcherLoop(
|
||||
urlConf.name,
|
||||
async () => {
|
||||
let interval: NodeJS.Timer;
|
||||
const res = await Axios.get(urlConf.address)
|
||||
|
||||
@@ -8,12 +8,13 @@ export function bmaWatcher(conf: Conf) {
|
||||
|
||||
return async (bmaServer: ConfBMA) => {
|
||||
|
||||
await urlWatcher(conf, async (data) => {
|
||||
return urlWatcher(conf, async (data) => {
|
||||
const block = data as { medianTime: number }
|
||||
if (bmaServer.maxLate && moment().unix() - block.medianTime > bmaServer.maxLate) {
|
||||
throw 'Server is late'
|
||||
}
|
||||
})({
|
||||
name: `BMA ${bmaServer.address}`,
|
||||
address: bmaServer.address + URL_PATH,
|
||||
frequency: bmaServer.frequency
|
||||
})
|
||||
|
||||
@@ -6,7 +6,7 @@ export function dprobeHeartbeat(conf: Conf) {
|
||||
|
||||
return async (dconf: ConfDprobeHeartbeat) => {
|
||||
|
||||
await urlWatcher(conf, async (data) => {
|
||||
return urlWatcher(conf, async (data) => {
|
||||
const last = moment(data, 'YYYY-MM-DD HH:mm:ss\n')
|
||||
const past = moment().diff(last)
|
||||
if (past > dconf.lastBeat) {
|
||||
|
||||
@@ -39,7 +39,8 @@ export function webDiffWatcher(conf: Conf) {
|
||||
}
|
||||
}
|
||||
|
||||
await watcherLoop(
|
||||
return watcherLoop(
|
||||
`webdiff ${target}`,
|
||||
async () => {
|
||||
const data1 = await Axios.get(webDiffConf.file1)
|
||||
const data2 = await Axios.get(webDiffConf.file2)
|
||||
|
||||
@@ -16,7 +16,8 @@ export function ws2pWatcher(conf: Conf) {
|
||||
const keypair = new Key(keys.pub, keys.sec)
|
||||
const target = `${wserver.address} (${wserver.expectedPubkey.substr(0, 8)})`
|
||||
|
||||
await watcherLoop(
|
||||
return watcherLoop(
|
||||
`WS2P ${wserver.address}`,
|
||||
async () => {
|
||||
|
||||
const localAuth = new WS2PPubkeyLocalAuth(wserver.currency, keypair, "", async () => true)
|
||||
|
||||
Reference in New Issue
Block a user