Skip to content

Commit

Permalink
Merge pull request #69 from developmentseed/2.2.6
Browse files Browse the repository at this point in the history
fix how p-retry handles exceptions (2.2.6 release)
  • Loading branch information
scisco authored Dec 10, 2018
2 parents a79237d + d84dc64 commit 449b418
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v2.2.6
- fix how p-retry handles exceptions
- add ifEquals and ifNotEquals helpers to handlerbar

## v2.2.5
- Add support for arbitrary parameters in the API Gateway methods
- retry CF describe calls for five times if the request is throttled
Expand Down
2 changes: 2 additions & 0 deletions examples/lambdas/cloudformation.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Resources:
# Lambda config BEGIN
#################################################
{{#each lambdas}}
{{#ifNotEquals this.handler "func3.handler"}}
{{@key}}LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Expand All @@ -69,6 +70,7 @@ Resources:
- Arn
Runtime: {{# if this.runtime}}{{this.runtime}}{{else}}nodejs6.10{{/if}}
Timeout: {{# if this.timeout}}{{this.timeout}}{{else}}300{{/if}}
{{/ifNotEquals}}
{{/each}}
#################################################
# Lambda config END
Expand Down
6 changes: 6 additions & 0 deletions examples/lambdas/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ default:
s3Source:
bucket: devseed-kes-deployment
key: example_lambdas/lambda.zip
func3:
handler: func3.handler
timeout: 300
s3Source:
bucket: devseed-kes-deployment
key: example_lambdas/lambda.zip

kesTestDeployment:
stackName: kes-test-project-prod
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kes",
"version": "2.2.5",
"version": "2.2.6",
"description": "Making deployment to AWS using CloudFormation easier and fun",
"scripts": {
"html-docs": "documentation build bin/cli.js -f html -o _docs --theme node_modules/documentation-devseed-theme",
Expand Down
26 changes: 19 additions & 7 deletions src/kes.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,20 @@ class Kes {
* the CF stack
*/
describeStack(stackName) {
const describe = () => this.cf.describeStacks({ StackName: stackName }).promise();
const describe = () => this.cf.describeStacks({
StackName: stackName
})
.promise()
.catch((error) => {
if (error.code !== 'ThrottlingException') {
throw new pRetry.AbortError(error.message, error);
}
throw error;
});

return pRetry(describe, {
onFailedAttempt: error => {
if (error.code === 'ThrottlingException') {
console.log(`Attempt ${error.attemptNumber} failed. There are ${error.attemptsLeft} attempts left.`);
}
else {
throw new pRetry.AbortError(error);
}
console.log(`Attempt ${error.attemptNumber} failed. There are ${error.attemptsLeft} attempts left.`);
},
retries: 5
});
Expand Down Expand Up @@ -104,6 +108,14 @@ class Kes {
return value;
});

Handlebars.registerHelper('ifEquals', function ifEquals(arg1, arg2, options) {
return (arg1 === arg2) ? options.fn(this) : options.inverse(this);
});

Handlebars.registerHelper('ifNotEquals', function ifNotEquals(arg1, arg2, options) {
return (arg1 !== arg2) ? options.fn(this) : options.inverse(this);
});

Handlebars.registerHelper('ToJson', function(value) {
return JSON.stringify(value);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/test.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test('create a config instance', (t) => {
});

t.is(config.stack, 'my-kes-project');
t.is(Object.keys(config.lambdas).length, 2);
t.is(Object.keys(config.lambdas).length, 3);
t.is(config.lambdas.func1.fullName, 'my-kes-project-func1');

// make sure envs are added even if lambdas don't include them
Expand Down

0 comments on commit 449b418

Please sign in to comment.