Skip to content

Commit

Permalink
fix(keystone): INFRA-289 add timeout status for healthcheck (#4499)
Browse files Browse the repository at this point in the history
  • Loading branch information
sitozzz authored Mar 20, 2024
1 parent a9051d8 commit 48b0b67
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/keystone/healthCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const DEFAULT_TIMEOUT = 5000 // 5s
const PASS = 'pass'
const WARN = 'warn'
const FAIL = 'fail'
const TIMEOUT = 'timeout'

const BAD_REQUEST = 400
const HEALTHCHECK_OK = 200
Expand Down Expand Up @@ -254,10 +255,10 @@ class HealthCheck {

const checkResult = await Promise.race([
check.run(),
new Promise(r => { setTimeout(r, DEFAULT_TIMEOUT) }).then(() => FAIL),
new Promise(r => { setTimeout(r, DEFAULT_TIMEOUT) }).then(() => TIMEOUT),
])

if (![PASS, WARN, FAIL].includes(checkResult)) {
if (![PASS, WARN, FAIL, TIMEOUT].includes(checkResult)) {
throw new Error(`Check.run function output not allowed value for check named ${check.name}`)
}
this.cache.set(check.name, checkResult)
Expand Down

0 comments on commit 48b0b67

Please sign in to comment.