[add] json-watcher
This commit is contained in:
@@ -6,6 +6,7 @@ export interface Conf {
|
||||
dprobeHeartbeats: ConfDprobeHeartbeat[]
|
||||
webDiffServers: ConfWebDiff[]
|
||||
headServers: ConfHead[]
|
||||
wwMeta: ConfWWMeta[]
|
||||
mail: ConfMail
|
||||
}
|
||||
|
||||
@@ -39,6 +40,10 @@ export interface ConfHead extends ConfURL {
|
||||
maxLateBlocks: number
|
||||
}
|
||||
|
||||
export interface ConfWWMeta extends ConfURL {
|
||||
maxLate: number
|
||||
}
|
||||
|
||||
export interface ConfDprobeHeartbeat extends ConfURL{
|
||||
lastBeat: number
|
||||
}
|
||||
|
||||
32
src/lib/watchers/wotwizard/json-watcher.ts
Normal file
32
src/lib/watchers/wotwizard/json-watcher.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import {Conf, ConfWWMeta} from "../../types/conf";
|
||||
import {urlWatcher} from '../abstract/url-watcher'
|
||||
|
||||
function handleLateness(confHead: ConfWWMeta, data: WWMetaJson) {
|
||||
const diff = Math.round(Date.now()/1000 - data.now)
|
||||
if (diff >= confHead.maxLate) {
|
||||
throw `WWMeta.json is late by ${diff}s (>= ${confHead.maxLate})`
|
||||
}
|
||||
}
|
||||
|
||||
export function jsonWatcher(conf: Conf) {
|
||||
|
||||
const URL_PATH = '/WWMeta.json'
|
||||
|
||||
return async (confWWMeta: ConfWWMeta) => {
|
||||
|
||||
return urlWatcher(conf, async (data) => {
|
||||
handleLateness(confWWMeta, data)
|
||||
})({
|
||||
name: `WWMeta.json watcher ${confWWMeta.address}`,
|
||||
address: confWWMeta.address + URL_PATH,
|
||||
frequency: confWWMeta.frequency
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
interface WWMetaJson {
|
||||
dossNb: number
|
||||
block: number
|
||||
now: number
|
||||
computation_duration: number
|
||||
}
|
||||
Reference in New Issue
Block a user