Merge branch 'Fix/dataFetching' into 'main'

reworked container data fetching

See merge request neshura-websites/www!6
This commit is contained in:
Neshura 2022-12-11 16:24:47 +00:00
commit dbf11d931e

View file

@ -107,6 +107,8 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
} }
// Type Docker // Type Docker
else if (entry.type === ServiceType.docker) { else if (entry.type === ServiceType.docker) {
if (entry.name !== null) {
let found = false;
for (let i = 0; i < containers.length; i++) { for (let i = 0; i < containers.length; i++) {
const container = containers[i]; const container = containers[i];
// Docker API returns container names with / prepended // Docker API returns container names with / prepended
@ -120,20 +122,25 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
console.log("Container Status " + container.State + " has no case implemented"); console.log("Container Status " + container.State + " has no case implemented");
entry.status = ServiceStatus.offline; entry.status = ServiceStatus.offline;
} }
found = true;
// cancel the for // cancel the for
break; break;
} }
// If container name is not missing the container is set to offline // If container name is not missing the container is set to offline
else if (entry.docker_container_name !== null) { else {
console.warn("Container for " + entry.name + " could not be found");
entry.status = ServiceStatus.offline; entry.status = ServiceStatus.offline;
} }
}
if (!found) {
console.warn("Container for " + entry.name + " could not be found");
}
}
// if name is null do not enter for loop
else { else {
console.error("Container Name not specified"); console.error("Container Name not specified");
entry.status = ServiceStatus.error; entry.status = ServiceStatus.error;
} }
} }
}
// If no Type matches // If no Type matches
else { else {
console.warn("Service Type for Service " + entry.name + " not specified or invalid"); console.warn("Service Type for Service " + entry.name + " not specified or invalid");