[add] json-watcher
This commit is contained in:
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