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,32 +107,39 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
} }
// Type Docker // Type Docker
else if (entry.type === ServiceType.docker) { else if (entry.type === ServiceType.docker) {
for (let i = 0; i < containers.length; i++) { if (entry.name !== null) {
const container = containers[i]; let found = false;
// Docker API returns container names with / prepended for (let i = 0; i < containers.length; i++) {
if (containers[i].Names.includes("/" + entry.docker_container_name)) { const container = containers[i];
// so far only "running" is properly implemented, mroe cases to follow as needed // Docker API returns container names with / prepended
switch (container.State) { if (containers[i].Names.includes("/" + entry.docker_container_name)) {
case "running": // so far only "running" is properly implemented, mroe cases to follow as needed
entry.status = ServiceStatus.online; switch (container.State) {
break; case "running":
default: entry.status = ServiceStatus.online;
console.log("Container Status " + container.State + " has no case implemented"); break;
entry.status = ServiceStatus.offline; default:
console.log("Container Status " + container.State + " has no case implemented");
entry.status = ServiceStatus.offline;
}
found = true;
// cancel the for
break;
}
// If container name is not missing the container is set to offline
else {
entry.status = ServiceStatus.offline;
} }
// cancel the for
break;
} }
// If container name is not missing the container is set to offline if (!found) {
else if (entry.docker_container_name !== null) {
console.warn("Container for " + entry.name + " could not be found"); console.warn("Container for " + entry.name + " could not be found");
entry.status = ServiceStatus.offline;
}
else {
console.error("Container Name not specified");
entry.status = ServiceStatus.error;
} }
} }
// if name is null do not enter for loop
else {
console.error("Container Name not specified");
entry.status = ServiceStatus.error;
}
} }
// If no Type matches // If no Type matches
else { else {