Replace foreach with for
This commit is contained in:
parent
3a617f9291
commit
bff352a395
1 changed files with 26 additions and 23 deletions
|
@ -86,7 +86,7 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
|
||||||
await fetch(entry.href)
|
await fetch(entry.href)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
switch(response.status) {
|
switch (response.status) {
|
||||||
case 200:
|
case 200:
|
||||||
case 301:
|
case 301:
|
||||||
case 302:
|
case 302:
|
||||||
|
@ -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 {
|
||||||
|
@ -147,26 +150,26 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
|
||||||
else if (entry.location === ServiceLocation.other) {
|
else if (entry.location === ServiceLocation.other) {
|
||||||
// Currently uses the same handling as app type for the other location
|
// Currently uses the same handling as app type for the other location
|
||||||
await fetch(entry.href)
|
await fetch(entry.href)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
switch(response.status) {
|
switch (response.status) {
|
||||||
case 200:
|
case 200:
|
||||||
case 301:
|
case 301:
|
||||||
case 302:
|
case 302:
|
||||||
entry.status = ServiceStatus.online;
|
entry.status = ServiceStatus.online;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
entry.status = ServiceStatus.offline;
|
entry.status = ServiceStatus.offline;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
entry.status = ServiceStatus.offline;
|
else {
|
||||||
}
|
entry.status = ServiceStatus.offline;
|
||||||
})
|
}
|
||||||
.catch((error) => {
|
})
|
||||||
console.error("Error pinging Website: ", error);
|
.catch((error) => {
|
||||||
entry.status = ServiceStatus.error;
|
console.error("Error pinging Website: ", error);
|
||||||
})
|
entry.status = ServiceStatus.error;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// If no Location matches
|
// If no Location matches
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in a new issue