From 469e33cbb6d1e8c7fb2d314c39f8661a70bad1bc Mon Sep 17 00:00:00 2001 From: "James M. Greene" Date: Tue, 28 Sep 2021 16:00:03 -0500 Subject: [PATCH] Allow Heroku `500` error codes while polling (#21795) * Extract allowable Heroku error checks into a reusable function * Add 500 to the list of allowable Heroku errors while polling --- script/deployment/deploy-to-production.js | 15 ++++++++++----- script/deployment/deploy-to-staging.js | 17 +++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/script/deployment/deploy-to-production.js b/script/deployment/deploy-to-production.js index 16f6c5831a..34b7e11f8d 100755 --- a/script/deployment/deploy-to-production.js +++ b/script/deployment/deploy-to-production.js @@ -8,9 +8,10 @@ const SLEEP_INTERVAL = 5000 const HEROKU_LOG_LINES_TO_SHOW = 25 const DELAY_FOR_PREBOOT_SWAP = 135000 // 2:15 -// Allow for a few 404 (Not Found) or 429 (Too Many Requests) responses from the -// semi-unreliable Heroku API when we're polling for status updates +// 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 ALLOWABLE_ERROR_CODES = [404, 429, 500] export default async function deployToProduction({ octokit, @@ -179,7 +180,7 @@ export default async function deployToProduction({ build = await heroku.get(`/apps/${appName}/builds/${buildId}`) } catch (error) { // Allow for a few bad responses from the Heroku API - if (error.statusCode === 404 || error.statusCode === 429) { + if (isAllowableHerokuError(error)) { buildAcceptableErrorCount += 1 if (buildAcceptableErrorCount <= ALLOWED_MISSING_RESPONSE_COUNT) { continue @@ -232,7 +233,7 @@ export default async function deployToProduction({ release = result } catch (error) { // Allow for a few bad responses from the Heroku API - if (error.statusCode === 404 || error.statusCode === 429) { + if (isAllowableHerokuError(error)) { releaseAcceptableErrorCount += 1 if (releaseAcceptableErrorCount <= ALLOWED_MISSING_RESPONSE_COUNT) { continue @@ -291,7 +292,7 @@ export default async function deployToProduction({ ) } catch (error) { // Allow for a few bad responses from the Heroku API - if (error.statusCode === 404 || error.statusCode === 429) { + if (isAllowableHerokuError(error)) { dynoAcceptableErrorCount += 1 if (dynoAcceptableErrorCount <= ALLOWED_MISSING_RESPONSE_COUNT) { continue @@ -440,6 +441,10 @@ async function getTarballUrl({ octokit, owner, repo, sha }) { return tarballUrl } +function isAllowableHerokuError(error) { + return error && ALLOWABLE_ERROR_CODES.includes(error.statusCode) +} + function announceIfHerokuIsDown(error) { if (error && error.statusCode === 503) { console.error('💀 Heroku may be down! Please check its Status page: https://status.heroku.com/') diff --git a/script/deployment/deploy-to-staging.js b/script/deployment/deploy-to-staging.js index f4ca082d21..9d48b2fb53 100644 --- a/script/deployment/deploy-to-staging.js +++ b/script/deployment/deploy-to-staging.js @@ -8,9 +8,10 @@ import createStagingAppName from './create-staging-app-name.js' const SLEEP_INTERVAL = 5000 const HEROKU_LOG_LINES_TO_SHOW = 25 -// Allow for a few 404 (Not Found) or 429 (Too Many Requests) responses from the -// semi-unreliable Heroku API when we're polling for status updates +// 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 ALLOWABLE_ERROR_CODES = [404, 429, 500] export default async function deployToStaging({ octokit, @@ -238,7 +239,7 @@ export default async function deployToStaging({ build = appSetup.build } catch (error) { // Allow for a few bad responses from the Heroku API - if (error.statusCode === 404 || error.statusCode === 429) { + if (isAllowableHerokuError(error)) { setupAcceptableErrorCount += 1 if (setupAcceptableErrorCount <= ALLOWED_MISSING_RESPONSE_COUNT) { continue @@ -321,7 +322,7 @@ See Heroku logs for more information:\n${logUrl}` build = await heroku.get(`/apps/${appName}/builds/${buildId}`) } catch (error) { // Allow for a few bad responses from the Heroku API - if (error.statusCode === 404 || error.statusCode === 429) { + if (isAllowableHerokuError(error)) { buildAcceptableErrorCount += 1 if (buildAcceptableErrorCount <= ALLOWED_MISSING_RESPONSE_COUNT) { continue @@ -374,7 +375,7 @@ See Heroku logs for more information:\n${logUrl}` release = result } catch (error) { // Allow for a few bad responses from the Heroku API - if (error.statusCode === 404 || error.statusCode === 429) { + if (isAllowableHerokuError(error)) { releaseAcceptableErrorCount += 1 if (releaseAcceptableErrorCount <= ALLOWED_MISSING_RESPONSE_COUNT) { continue @@ -480,7 +481,7 @@ See Heroku logs for more information:\n${logUrl}` ) } catch (error) { // Allow for a few bad responses from the Heroku API - if (error.statusCode === 404 || error.statusCode === 429) { + if (isAllowableHerokuError(error)) { dynoAcceptableErrorCount += 1 if (dynoAcceptableErrorCount <= ALLOWED_MISSING_RESPONSE_COUNT) { continue @@ -646,6 +647,10 @@ async function getTarballUrl({ octokit, owner, repo, sha }) { return tarballUrl } +function isAllowableHerokuError(error) { + return error && ALLOWABLE_ERROR_CODES.includes(error.statusCode) +} + function announceIfHerokuIsDown(error) { if (error && error.statusCode === 503) { console.error('💀 Heroku may be down! Please check its Status page: https://status.heroku.com/')