Fixed health checker.

This commit is contained in:
BurnyLlama 2022-05-28 16:29:45 +02:00
parent dffd4b0507
commit 5d4a3baef3

View File

@ -5,6 +5,7 @@ import https from "https"
const log = getLogger("Health Checker", settings.checkers["health-checker"].color)
// This function is a mess -- I know.
function checkService(serviceDomain) {
log(`Checking service '${serviceDomain}'`)
return new Promise(
@ -15,10 +16,12 @@ function checkService(serviceDomain) {
path: "/",
method: "GET"
}, res => {
if (res.statusCode === 200) resolve(`Service '${serviceDomain}' seems to be running!`)
res.on("error", () => reject(`Service '${serviceDomain}' seems to have stopped!`))
res.on("error", () => reject())
res.on("end", () => res.statusCode === 200 ? resolve() : reject())
res.on("close", () => res.statusCode === 200 ? resolve() : reject())
return res.statusCode === 200 ? resolve() : reject()
})
req.on("error", () => reject(`Service '${serviceDomain}' seems to have stopped!`))
req.on("error", () => reject())
req.end()
}
)
@ -31,11 +34,12 @@ export function start(sendMessage) {
function checkServices(serviceDomains) {
for (const serviceDomain of serviceDomains) {
checkService(serviceDomain).then(
status => log(status)
() => log(`Service '${serviceDomain}' seems to be running!`)
).catch(
status => {
log(status)
sendMessage(status)
() => {
const message = `**IMPORTANT!** Service '${serviceDomain}' seems to have stopped!`
log(message)
sendMessage(message)
}
)
}