Fix logic bug with isDown

This commit is contained in:
Lumeille 2024-06-02 18:33:26 +10:00
parent 1fdcdc69c0
commit 8f729caa51
1 changed files with 1 additions and 1 deletions

View File

@ -7,7 +7,6 @@ type EndpointState = State extends Map<any, infer L> ? L : never
export const handleDown = (endpointState: EndpointState, curTime: number, endpoint: Config["pollEndpoints"][number]) => { export const handleDown = (endpointState: EndpointState, curTime: number, endpoint: Config["pollEndpoints"][number]) => {
const prevDown = endpointState.isDown const prevDown = endpointState.isDown
endpointState.isDown = true
endpointState.attemptsFailed++ endpointState.attemptsFailed++
console.log(`Endpoint ${endpoint.name} has failed ${endpointState.attemptsFailed} times`) console.log(`Endpoint ${endpoint.name} has failed ${endpointState.attemptsFailed} times`)
@ -17,6 +16,7 @@ export const handleDown = (endpointState: EndpointState, curTime: number, endpoi
if (curTime - endpointState.lastDownAlert < (endpoint.notifyInterval) * 1000) return if (curTime - endpointState.lastDownAlert < (endpoint.notifyInterval) * 1000) return
if (endpointState.attemptsFailed > (endpoint.retries ?? config.defaults.retries)) { if (endpointState.attemptsFailed > (endpoint.retries ?? config.defaults.retries)) {
endpointState.isDown = true
const message = prevDown ? const message = prevDown ?
`[${formatTS(curTime)}] ${endpoint.name} is still down and initially went down at ${formatTS(endpointState.downStart)}` : `[${formatTS(curTime)}] ${endpoint.name} is still down and initially went down at ${formatTS(endpointState.downStart)}` :
`[${formatTS(curTime)}] ${endpoint.name} went down` `[${formatTS(curTime)}] ${endpoint.name} went down`