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

@ -86,7 +86,7 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
await fetch(entry.href)
.then((response) => {
if (response.ok) {
switch(response.status) {
switch (response.status) {
case 200:
case 301:
case 302:
@ -107,9 +107,10 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
}
// Type 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
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
switch (container.State) {
case "running":
@ -119,6 +120,8 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
console.log("Container Status " + container.State + " has no case implemented");
entry.status = ServiceStatus.offline;
}
// cancel the for
break;
}
// If container name is not missing the container is set to offline
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");
entry.status = ServiceStatus.error;
}
})
}
}
// If no Type matches
else {
@ -149,7 +152,7 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
await fetch(entry.href)
.then((response) => {
if (response.ok) {
switch(response.status) {
switch (response.status) {
case 200:
case 301:
case 302: