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;
}
async init(logger) {
this.conf = logger.conf;
setInterval(() => this.getSalixVersion, this.conf.salix.renewInterval);
await this.salixLogInfo();
}
async getSalixVersion(){
console.log("SALIX - CHECK VERSION");
let salixCall = await fetch(`${this.conf.salix.url}/applications/version`, {
async fetch(path) {
let salixCall = await fetch(`${this.conf.salix.url}/${path}`, {
method: "GET",
});
let salixVersion = JSON.parse(await salixCall.text());
console.log("SALIX - VERSION CHECKED");
const response = JSON.parse(await salixCall.text());
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();
log("VERSION CHECKED");
}
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._logInfo = salixLogConfig
console.log("SALIX- LOGINFO REQUESTED");
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
return this._logInfo;
}
get salixVersion() {