1
0
mirror of synced 2025-12-22 03:16:52 -05:00

Do not use build.status as a looping condition for Heroku deployment (#21909)

* Do not use `build.status` of 'pending' as a looping condition for Heroku deployment
* Don't wait for `appSetup.status` either
* Fix incorrect Octokit method usage in local deploy script
* Bump the number of allowable errors from 5 to 10
* More logging!
* Add an environment variable for easily increasing the number of allowed Heroku failures per phase of polling
This commit is contained in:
James M. Greene
2021-10-06 12:57:30 -05:00
committed by GitHub
parent 7f7f06e2ba
commit bb0455962e
5 changed files with 36 additions and 8 deletions

View File

@@ -10,7 +10,8 @@ const DELAY_FOR_PREBOOT_SWAP = 135000 // 2:15
// Allow for a few 404 (Not Found), 429 (Too Many Requests), etc. responses from
// the semi-unreliable Heroku API when we're polling for status updates
const ALLOWED_MISSING_RESPONSE_COUNT = 5
const ALLOWED_MISSING_RESPONSE_COUNT =
parseInt(process.env.ALLOWED_POLLING_FAILURES_PER_PHASE, 10) || 10
const ALLOWABLE_ERROR_CODES = [404, 429, 500, 503]
export default async function deployToProduction({
@@ -175,7 +176,7 @@ export default async function deployToProduction({
// Poll until the Build's status changes from "pending" to "succeeded" or "failed".
let buildAcceptableErrorCount = 0
while (!build || build.status === 'pending' || !build.release || !build.release.id) {
while (!build || !build.release || !build.release.id) {
await sleep(SLEEP_INTERVAL)
try {
build = await heroku.get(`/apps/${appName}/builds/${buildId}`)
@@ -184,6 +185,9 @@ export default async function deployToProduction({
if (isAllowableHerokuError(error)) {
buildAcceptableErrorCount += 1
if (buildAcceptableErrorCount <= ALLOWED_MISSING_RESPONSE_COUNT) {
console.warn(
`Ignoring allowable Heroku error #${buildAcceptableErrorCount}: ${error.statusCode}`
)
continue
}
}
@@ -210,6 +214,7 @@ export default async function deployToProduction({
`Finished Heroku build after ${Math.round((Date.now() - buildStartTime) / 1000)} seconds.`,
build
)
console.log('Heroku release detected', build.release)
const releaseStartTime = Date.now() // Close enough...
const releaseId = build.release.id
@@ -237,6 +242,9 @@ export default async function deployToProduction({
if (isAllowableHerokuError(error)) {
releaseAcceptableErrorCount += 1
if (releaseAcceptableErrorCount <= ALLOWED_MISSING_RESPONSE_COUNT) {
console.warn(
`Ignoring allowable Heroku error #${releaseAcceptableErrorCount}: ${error.statusCode}`
)
continue
}
}
@@ -296,6 +304,9 @@ export default async function deployToProduction({
if (isAllowableHerokuError(error)) {
dynoAcceptableErrorCount += 1
if (dynoAcceptableErrorCount <= ALLOWED_MISSING_RESPONSE_COUNT) {
console.warn(
`Ignoring allowable Heroku error #${dynoAcceptableErrorCount}: ${error.statusCode}`
)
continue
}
}