perf: #6533 class Salix

This commit is contained in:
Javier Segarra 2024-04-25 07:34:32 +02:00
parent e836dc08ec
commit be89b664aa
1 changed files with 35 additions and 22 deletions

View File

@ -5,36 +5,49 @@ module.exports = class Salix {
this._salixVersion = null; this._salixVersion = null;
} }
async init(logger) { async init(logger) {
this.conf = logger.conf; this.conf = logger.conf;
setInterval(() => this.getSalixVersion, this.conf.salix.renewInterval); setInterval(() => this.getSalixVersion, this.conf.salix.renewInterval);
await this.salixLogInfo(); await this.salixLogInfo();
} }
async getSalixVersion(){ async fetch(path) {
console.log("SALIX - CHECK VERSION"); let salixCall = await fetch(`${this.conf.salix.url}/${path}`, {
let salixCall = await fetch(`${this.conf.salix.url}/applications/version`, {
method: "GET", method: "GET",
}); });
let salixVersion = JSON.parse(await salixCall.text()); const response = JSON.parse(await salixCall.text());
console.log("SALIX - VERSION CHECKED"); if (salixCall.status !== 200) {
console.error(response.error);
throw new Error(response.error.message);
}
this._salixVersion = salixCall.headers.get("Salix-version");
return response;
}
async getSalixVersion() {
log("CHECK VERSION");
const salixVersion = await this.fetch("applications/version");
if (this._salixVersion !== salixVersion) fetch(); if (this._salixVersion !== salixVersion) fetch();
log("VERSION CHECKED");
} }
async salixLogInfo() { async salixLogInfo() {
console.log("SALIX - LOGINFO REQUEST"); log("LOGINFO REQUEST");
let salixCall = await fetch(`${this.conf.salix.url}/schemas/logInfo`, { let salixLogConfig = await this.fetch("schemas/logInfo");
method: "GET",
}); this._logInfo = [salixLogConfig];
let salixLogConfig = [JSON.parse(await salixCall.text())];
this._salixVersion = salixCall.headers.get("Salix-version"); log("LOGINFO REQUESTED");
this._logInfo = salixLogConfig }
console.log("SALIX- LOGINFO REQUESTED");
log(param) {
console.log(`${Salix.name} - ${param}`);
} }
get logInfo() { get logInfo() {
return this._logInfo return this._logInfo;
} }
get salixVersion() { get salixVersion() {