From 3519106bbf526b44fe821ec13bd7bc4ba1c68c60 Mon Sep 17 00:00:00 2001 From: cgeek Date: Thu, 30 Apr 2020 15:28:06 +0200 Subject: [PATCH] [add] json-watcher --- app.yml | 5 ++++ src/lib/types/conf.ts | 5 ++++ src/lib/watchers/wotwizard/json-watcher.ts | 32 ++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/lib/watchers/wotwizard/json-watcher.ts diff --git a/app.yml b/app.yml index f82747f..c325c66 100644 --- a/app.yml +++ b/app.yml @@ -29,6 +29,11 @@ headServers: maxLateBlocks: 3 observedPubkey: A5LQXCkx8b6rzppfqdqeHbKPDGmKZtRcqwxP4BSeag5r +wwMeta: + - address: https://wot-wizard.duniter.org + frequency: 60000 # 1' + maxLate: 14400 # 4h + mail: enabled: false host: smtp.sparkpostmail.com diff --git a/src/lib/types/conf.ts b/src/lib/types/conf.ts index db460e4..cedcb4e 100644 --- a/src/lib/types/conf.ts +++ b/src/lib/types/conf.ts @@ -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 } diff --git a/src/lib/watchers/wotwizard/json-watcher.ts b/src/lib/watchers/wotwizard/json-watcher.ts new file mode 100644 index 0000000..83c6d63 --- /dev/null +++ b/src/lib/watchers/wotwizard/json-watcher.ts @@ -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 +} \ No newline at end of file