From ca99705eac2e8444be4d93b71dea2706f0d3c01b Mon Sep 17 00:00:00 2001 From: merlin Gaillard Date: Mon, 7 Nov 2016 11:22:43 +0100 Subject: [PATCH] Look for ROLLBACK_COMPLETE when polling event and exit if found Fix #12 --- src/utils.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/utils.js b/src/utils.js index 11ac43e..79a8469 100644 --- a/src/utils.js +++ b/src/utils.js @@ -264,6 +264,18 @@ export default function (argv, cloudformation) { } function pollEvents (stackName, actionName, matches, callback, opts = {}) { + const failureMatches = [ + [ 'LogicalResourceId', stackName ], + [ 'ResourceStatus', 'ROLLBACK_COMPLETE' ] + ] + const failureCallback = function (err) { + if (err) { + throw err + } + console.log(`${stackName} failed!`.red) + process.exit() + } + function checkEvents (lastDate) { const now = new Date() @@ -295,8 +307,16 @@ export default function (argv, cloudformation) { spinner.destroy() return callback() } + if (failureMatches.every(function (match) { + return events[i][match[0]] === match[1] + })) { + spinner.destroy() + return failureCallback() + } } + + return next() function next () {