From 67c474087207c4b55b209a6c2b7d99ea1eaae14f Mon Sep 17 00:00:00 2001 From: cgeek Date: Fri, 8 May 2020 11:19:21 +0200 Subject: [PATCH] [mod] have a unique value of reconnection delay --- app.yml | 32 ++------------------- src/lib/types/conf.ts | 2 +- src/lib/watcherLoop.ts | 3 +- src/lib/watchers/abstract/url-watcher.ts | 2 +- src/lib/watchers/webdiff/webdiff-watcher.ts | 2 +- src/lib/watchers/ws2p/ws2p-watcher.ts | 2 +- 6 files changed, 7 insertions(+), 36 deletions(-) diff --git a/app.yml b/app.yml index 3b9a8f5..7ba7b3a 100644 --- a/app.yml +++ b/app.yml @@ -1,4 +1,5 @@ -connectionTimeout: 10000 +connectionTimeout: 10000 # 10" +waitingDelay: 60000 # 1' ws2pServers: - address: ws://g1-test.cgeek.fr:22001 expectedPubkey: 3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj @@ -44,32 +45,3 @@ mail: apikey: 6976eb51635b680b832dbe4914524d2c038a13b6 from: '"DWatcher" ' to: cem.moreau@gmail.com - -reconnectionDelays: - - 5000 - - 10000 - - 15000 - - 30000 - - 60000 # 1' - - 300000 # 5' - - 600000 # 10' - - 900000 # 15' - - 1200000 # 20' - - 1800000 # 30' - - 2400000 # 40' - - 3000000 # 50' - - 3600000 # 1h - - 3600000 # 1h - - 3600000 # 1h - - 3600000 # 1h - - 7200000 # 2h - - 7200000 # 2h - - 7200000 # 2h - - 7200000 # 2h - - 14400000 # 4h - - 14400000 # 4h - - 14400000 # 4h - - 14400000 # 4h - - 21600000 # 6h - - 21600000 # 6h - - 43200000 # 12h diff --git a/src/lib/types/conf.ts b/src/lib/types/conf.ts index cedcb4e..5384048 100644 --- a/src/lib/types/conf.ts +++ b/src/lib/types/conf.ts @@ -1,6 +1,6 @@ export interface Conf { connectionTimeout: number - reconnectionDelays: number[] + waitingDelay: number ws2pServers: ConfWS2P[] bmaServers: ConfBMA[] dprobeHeartbeats: ConfDprobeHeartbeat[] diff --git a/src/lib/watcherLoop.ts b/src/lib/watcherLoop.ts index b38a4e9..d5c8998 100644 --- a/src/lib/watcherLoop.ts +++ b/src/lib/watcherLoop.ts @@ -4,7 +4,7 @@ export function watcherLoop( name: string, connect: () => Promise, onConnectionClosed: () => Promise, - reconnectionDelays: number[], + waitingDelay: number, onStart: () => Promise, onDisconnection: (waitingDelay: number, error: any) => Promise, onRestart: () => Promise, @@ -46,7 +46,6 @@ export function watcherLoop( watcher.stateFailure(e) } // Wait before reconnecting - const waitingDelay = reconnectionDelays[Math.min(reconnectionDelays.length - 1, i)] if (watcher.stateChanged) { // Notify only if state changed since await onDisconnection(waitingDelay, watcher.error) diff --git a/src/lib/watchers/abstract/url-watcher.ts b/src/lib/watchers/abstract/url-watcher.ts index 0f449ce..c88b929 100644 --- a/src/lib/watchers/abstract/url-watcher.ts +++ b/src/lib/watchers/abstract/url-watcher.ts @@ -44,7 +44,7 @@ export function urlWatcher(conf: Conf, checkValidity: (data: any) => Promise nodeDownPromise, - conf.reconnectionDelays, + conf.waitingDelay, mail.onEstablished(conf, urlConf.address, getOkTitle()), diff --git a/src/lib/watchers/webdiff/webdiff-watcher.ts b/src/lib/watchers/webdiff/webdiff-watcher.ts index fea9383..3dec296 100644 --- a/src/lib/watchers/webdiff/webdiff-watcher.ts +++ b/src/lib/watchers/webdiff/webdiff-watcher.ts @@ -61,7 +61,7 @@ export function webDiffWatcher(conf: Conf) { () => nodeDownPromise, - conf.reconnectionDelays, + conf.waitingDelay, () => mail.onEstablished(conf, target, 'webdiff successfully started')(webDiffConf.cc), diff --git a/src/lib/watchers/ws2p/ws2p-watcher.ts b/src/lib/watchers/ws2p/ws2p-watcher.ts index 9908ebf..1c4d561 100644 --- a/src/lib/watchers/ws2p/ws2p-watcher.ts +++ b/src/lib/watchers/ws2p/ws2p-watcher.ts @@ -42,7 +42,7 @@ export function ws2pWatcher(conf: Conf) { () => c.closed, - conf.reconnectionDelays, + conf.waitingDelay, mail.onEstablished(conf, target),