remove stale nodes

This commit is contained in:
ElevenNotes
2024-02-01 11:29:08 +01:00
parent b18b3f67be
commit 16ceb5a17a
2 changed files with 19 additions and 3 deletions

View File

@@ -54,6 +54,8 @@ class Labels{
if(!this.#loops.nodes){
this.#loops.nodes = true;
try{
elevenLogJSON('info', `reload nodes from config.yaml`);
this.#config = yaml.load(fs.readFileSync(`${process.env.APP_ROOT}/etc/config.yaml`, 'utf8'))?.labels;
await this.#loadNodes(false);
}catch(e){
elevenLogJSON('error', JSON.stringify({nodes:{exception:e.toString()}}));
@@ -77,6 +79,20 @@ class Labels{
this.#nodes[node].labels = {ping:false, firstConnect:init};
}
}
for(const pnode in this.#nodes){
let valid = false;
for(const node of this.#config?.nodes){
if(pnode === node){
valid = true;
break;
}
}
if(!valid){
elevenLogJSON('info', `removed node [${pnode}] from configuration`);
delete(this.#nodes[pnode]);
}
}
}
async watch(){