1
0
mirror of synced 2025-12-30 03:01:36 -05:00

improvements from @peterbe

This commit is contained in:
Evan Bonsignori
2022-08-18 11:15:20 -07:00
parent abcf940a00
commit 931bb63733
3 changed files with 13 additions and 25 deletions

View File

@@ -31,7 +31,7 @@ const PROD_URL = 'https://docs.github.com'
run()
async function run() {
const isHealthy = await waitUntilUrlIsHealthy(APP_URL)
const isHealthy = await waitUntilUrlIsHealthy(new URL('/healthz', APP_URL).toString())
if (!isHealthy) {
return core.setFailed(`Timeout waiting for preview environment: ${APP_URL}`)
}

View File

@@ -6,29 +6,17 @@ const DELAY_SECONDS = 15
/*
* Promise resolves once url is healthy or fails if timeout has passed
* @param {string} url - path to server
* @param {string} [healthPath] - endpoint to health check, e.g. "healthz"
* @param {string} url - health url, e.g. docs.com/healthz
*/
export async function waitUntilUrlIsHealthy(url, healthPath = 'healthz') {
let attempt = 1
while (attempt < RETRIES) {
try {
const res = await got.head(`${url}/${healthPath}`)
if (res.statusCode === 200) {
return true
}
} catch (err) {}
// Delay before next attempt
await sleep(DELAY_SECONDS)
attempt++
}
export async function waitUntilUrlIsHealthy(url) {
try {
await got.head(url, {
retry: {
limit: RETRIES,
calculateDelay: () => DELAY_SECONDS * 1000,
},
})
return true
} catch {}
return false
}
/*
* Async-await sleep
* @param {string} seconds - Seconds to sleep
*/
export async function sleep(seconds) {
return new Promise((resolve) => setTimeout(resolve, seconds * 1000))
}

View File

@@ -68,7 +68,7 @@ jobs:
- name: Get changes table
id: changes
timeout-minutes: 20
timeout-minutes: 30
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APP_URL: ${{ env.APP_URL }}