Skip to content

Commit

Permalink
Merge pull request #220 from bustle/respect_limits
Browse files Browse the repository at this point in the history
Add automatic retry to deploys
  • Loading branch information
chris-olszewski authored May 22, 2017
2 parents 49e1dbe + 6ff3634 commit 95bcc28
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/util/aws/api-gateway.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import AWS from './'
import Promise from 'bluebird'

export const DEPLOY_ATTEMPT_MAX = 2

export function exportStage (restApiId, stageName) {
const apiGateway = new AWS.APIGateway()
Expand All @@ -16,9 +19,14 @@ export function exportStage (restApiId, stageName) {
.get('body')
}

export function deploy (id, env) {
export function deploy (id, env, attempts = 1) {
const apiGateway = new AWS.APIGateway()
return apiGateway.createDeployment({restApiId: id, stageName: env, variables: { functionAlias: env }}).promise()
.catch({ code: 'TooManyRequestsException' }, async ({ retryable, retryDelay }) => {
if (!retryable && attempts > DEPLOY_ATTEMPT_MAX) { throw new Error('Amazon limit hit') }
await Promise.delay(retryDelay * 1000)
return deploy(id, env, attempts++)
})
}

export function pushApi (api, id) {
Expand Down

0 comments on commit 95bcc28

Please sign in to comment.