1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/src/workflows/wait-until-url-is-healthy.ts
2024-12-02 17:29:09 +00:00

23 lines
554 B
TypeScript

import got from 'got'
// Will try for 20 minutes, (15 * 80) seconds / 60 [seconds]
const RETRIES = 80
const DELAY_SECONDS = 15
/*
* Promise resolves once url is healthy or fails if timeout has passed
* @param {string} url - health url, e.g. docs.com/healthz
*/
export async function waitUntilUrlIsHealthy(url: string) {
try {
await got.head(url, {
retry: {
limit: RETRIES,
calculateDelay: ({ computedValue }) => Math.min(computedValue, DELAY_SECONDS * 1000),
},
})
return true
} catch {}
return false
}