broadcast status updates

This commit is contained in:
Erik 2023-10-14 13:01:36 +03:00
parent 1a45c35090
commit 9fce8c72ff
2 changed files with 15 additions and 9 deletions

View File

@ -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 });
}
}

View File

@ -5,10 +5,15 @@ export type LoggerClientOptions = {
logLevelMapping: {[key: string]: number}
}
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
type WriteOptions = {
subheader?: string,
broadcast?: boolean
}
export interface ILogger {
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
}