Replace foreach with for

This commit is contained in:
Neshura 2022-12-11 17:11:02 +01:00
parent 3a617f9291
commit bff352a395
No known key found for this signature in database
GPG key ID: ACDF5B6EBECF6B0A

View file

@ -107,9 +107,10 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
} }
// Type Docker // Type Docker
else if (entry.type === ServiceType.docker) { else if (entry.type === ServiceType.docker) {
containers.forEach((container) => { for (let i = 0; i < containers.length; i++) {
const container = containers[i];
// Docker API returns container names with / prepended // Docker API returns container names with / prepended
if (container.Names.includes("/" + entry.docker_container_name)) { if (containers[i].Names.includes("/" + entry.docker_container_name)) {
// so far only "running" is properly implemented, mroe cases to follow as needed // so far only "running" is properly implemented, mroe cases to follow as needed
switch (container.State) { switch (container.State) {
case "running": case "running":
@ -119,6 +120,8 @@ 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;
} }
// cancel the for
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 if (entry.docker_container_name !== null) {
@ -134,7 +137,7 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
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 {