Fixed health checker.
This commit is contained in:
parent
dffd4b0507
commit
5d4a3baef3
|
@ -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)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user