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,39 +5,52 @@ 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) {
if(this._salixVersion !== salixVersion) fetch(); console.error(response.error);
} throw new Error(response.error.message);
}
async salixLogInfo() {
console.log("SALIX - LOGINFO REQUEST");
let salixCall = await fetch(`${this.conf.salix.url}/schemas/logInfo`, {
method: "GET",
});
let salixLogConfig = [JSON.parse(await salixCall.text())];
this._salixVersion = salixCall.headers.get("Salix-version"); this._salixVersion = salixCall.headers.get("Salix-version");
this._logInfo = salixLogConfig return response;
console.log("SALIX- LOGINFO REQUESTED");
} }
get logInfo(){ async getSalixVersion() {
return this._logInfo log("CHECK VERSION");
const salixVersion = await this.fetch("applications/version");
if (this._salixVersion !== salixVersion) fetch();
log("VERSION CHECKED");
} }
get salixVersion(){ async salixLogInfo() {
log("LOGINFO REQUEST");
let salixLogConfig = await this.fetch("schemas/logInfo");
this._logInfo = [salixLogConfig];
log("LOGINFO REQUESTED");
}
log(param) {
console.log(`${Salix.name} - ${param}`);
}
get logInfo() {
return this._logInfo;
}
get salixVersion() {
return this._salixVersion; return this._salixVersion;
} }
}; };