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/types/state.ts b/src/lib/types/state.ts index 6446de5..dc6ccce 100644 --- a/src/lib/types/state.ts +++ b/src/lib/types/state.ts @@ -1,20 +1,25 @@ export class Watcher { private _state: 'INIT'|'OK'|'FAILURE'|'RECOVERED' + private _stateChanged: boolean private _error?: any constructor(public readonly name: string) { + this._stateChanged = false this._state = "INIT" } public stateOK() { + this._stateChanged = this._state !== "OK" this._state = "OK" } public stateRecovered() { + this._stateChanged = this._state !== "RECOVERED" this._state = "RECOVERED" } public stateFailure(error: any) { + this._stateChanged = this._state !== "FAILURE" this._state = "FAILURE" this._error = error } @@ -23,6 +28,10 @@ export class Watcher { return this._state } + public get stateChanged() { + return this._stateChanged + } + public get error() { return this._error } diff --git a/src/lib/watcherLoop.ts b/src/lib/watcherLoop.ts index 4e1c83a..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,8 +46,10 @@ export function watcherLoop( watcher.stateFailure(e) } // Wait before reconnecting - const waitingDelay = reconnectionDelays[Math.min(reconnectionDelays.length - 1, i)] - await onDisconnection(waitingDelay, watcher.error) + if (watcher.stateChanged) { + // Notify only if state changed since + await onDisconnection(waitingDelay, watcher.error) + } await new Promise(resolve => setTimeout(resolve, waitingDelay)) i++ } 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),