From 9fce8c72ff75eadbd99f5552e06d6f1193d234f6 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sat, 14 Oct 2023 13:01:36 +0300 Subject: [PATCH] broadcast status updates --- src/MariaDB.ts | 9 +++++---- src/interfaces/Logger.ts | 15 ++++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/MariaDB.ts b/src/MariaDB.ts index 04289f6..91c2d45 100644 --- a/src/MariaDB.ts +++ b/src/MariaDB.ts @@ -277,7 +277,7 @@ class MariaDB { const oldStatus = node.status; node.status = 'disconnected'; - this.#logger.status(`Cluster node ${node.name} changed status from ${oldStatus} to ${node.status}`); + this.#logger.status(`Cluster node ${node.name} changed status from ${oldStatus} to ${node.status}`, { broadcast: true }); } }); else if (update.status === 'synced') @@ -289,7 +289,7 @@ class MariaDB { const oldStatus = node.status; node.status = 'synced'; - this.#logger.status(`Cluster node ${node.name} changed status from ${oldStatus} to ${node.status}`); + this.#logger.status(`Cluster node ${node.name} changed status from ${oldStatus} to ${node.status}`, { broadcast: true }); } }); } @@ -299,6 +299,7 @@ class MariaDB const index = parseInt(update.index); if (index === -1) return this.#logger.warn('Received -1 index, member does not recognise itself'); + const member = members[index]; const [ id,, host ] = member.split('/'); let node = this.#nodes.find(n => n.uuid === id); @@ -307,7 +308,7 @@ class MariaDB const [ ip ] = host.split(':'); node = this.#nodes.find(n => n.host === ip); if (!node) - return this.#logger.warn('Received status update for node that is not present in config'); + return this.#logger.warn('Received status update for node that is not present in config', { broadcast: true }); node.uuid = id; } @@ -315,7 +316,7 @@ class MariaDB { const oldStatus = node.status; node.status = update.status; - this.#logger.status(`Cluster node ${node.name} changed status from ${oldStatus} to ${node.status}`); + this.#logger.status(`Cluster node ${node.name} changed status from ${oldStatus} to ${node.status}`, { broadcast: true }); } } diff --git a/src/interfaces/Logger.ts b/src/interfaces/Logger.ts index 4c2b2e6..aacf953 100644 --- a/src/interfaces/Logger.ts +++ b/src/interfaces/Logger.ts @@ -5,10 +5,15 @@ export type LoggerClientOptions = { logLevelMapping: {[key: string]: number} } +type WriteOptions = { + subheader?: string, + broadcast?: boolean +} + export interface ILogger { - info(str: string | object): void - status(str: string | object): void - debug(str: string | object): void - warn(str: string | object): void - error(str: string | object): void + info(str: string | object, opts?: WriteOptions): void + status(str: string | object, opts?: WriteOptions): void + debug(str: string | object, opts?: WriteOptions): void + warn(str: string | object, opts?: WriteOptions): void + error(str: string | object, opts?: WriteOptions): void } \ No newline at end of file