Compare commits

...

2 Commits

Author SHA1 Message Date
8a03f4e171 1.6.7 2023-10-14 13:04:34 +03:00
9fce8c72ff broadcast status updates 2023-10-14 13:01:36 +03:00
3 changed files with 16 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@navy.gif/wrappers", "name": "@navy.gif/wrappers",
"version": "1.6.6", "version": "1.6.7",
"description": "Various wrapper classes I use in my projects", "description": "Various wrapper classes I use in my projects",
"repository": "https://git.corgi.wtf/Navy.gif/wrappers.git", "repository": "https://git.corgi.wtf/Navy.gif/wrappers.git",
"author": "Navy.gif", "author": "Navy.gif",

View File

@ -277,7 +277,7 @@ class MariaDB
{ {
const oldStatus = node.status; const oldStatus = node.status;
node.status = 'disconnected'; 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') else if (update.status === 'synced')
@ -289,7 +289,7 @@ class MariaDB
{ {
const oldStatus = node.status; const oldStatus = node.status;
node.status = 'synced'; 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); const index = parseInt(update.index);
if (index === -1) if (index === -1)
return this.#logger.warn('Received -1 index, member does not recognise itself'); return this.#logger.warn('Received -1 index, member does not recognise itself');
const member = members[index]; const member = members[index];
const [ id,, host ] = member.split('/'); const [ id,, host ] = member.split('/');
let node = this.#nodes.find(n => n.uuid === id); let node = this.#nodes.find(n => n.uuid === id);
@ -307,7 +308,7 @@ class MariaDB
const [ ip ] = host.split(':'); const [ ip ] = host.split(':');
node = this.#nodes.find(n => n.host === ip); node = this.#nodes.find(n => n.host === ip);
if (!node) 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; node.uuid = id;
} }
@ -315,7 +316,7 @@ class MariaDB
{ {
const oldStatus = node.status; const oldStatus = node.status;
node.status = update.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 });
} }
} }

View File

@ -5,10 +5,15 @@ export type LoggerClientOptions = {
logLevelMapping: {[key: string]: number} logLevelMapping: {[key: string]: number}
} }
type WriteOptions = {
subheader?: string,
broadcast?: boolean
}
export interface ILogger { export interface ILogger {
info(str: string | object): void info(str: string | object, opts?: WriteOptions): void
status(str: string | object): void status(str: string | object, opts?: WriteOptions): void
debug(str: string | object): void debug(str: string | object, opts?: WriteOptions): void
warn(str: string | object): void warn(str: string | object, opts?: WriteOptions): void
error(str: string | object): void error(str: string | object, opts?: WriteOptions): void
} }