Skip to content

Commit

Permalink
Merge pull request serverless#3297 from serverless/fix-monitor-stack-…
Browse files Browse the repository at this point in the history
…freezing-bug

Fix monitorStack freezing bug
  • Loading branch information
eahefnawy authored Feb 28, 2017
2 parents 010fe8b + 43a721e commit af3d463
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions lib/plugins/aws/lib/monitorStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ module.exports = {
'DELETE_COMPLETE',
];
const loggedEvents = [];
const monitoredSince = new Date();
monitoredSince.setSeconds(monitoredSince.getSeconds() - 5);

let monitoredSince = null;
let stackStatus = null;
let stackLatestError = null;

Expand All @@ -41,9 +40,33 @@ module.exports = {
this.options.stage,
this.options.region)
.then((data) => {
const stackEvents = data.StackEvents;

// look through all the stack events and find the first relevant
// event which is a "Stack" event and has a CREATE, UPDATE or DELETE status
const firstRelevantEvent = stackEvents.find((event) => {
const isStack = 'AWS::CloudFormation::Stack';
const updateIsInProgress = 'UPDATE_IN_PROGRESS';
const createIsInProgress = 'CREATE_IN_PROGRESS';
const deleteIsInProgress = 'DELETE_IN_PROGRESS';

return event.ResourceType === isStack
&& (event.ResourceStatus === updateIsInProgress
|| event.ResourceStatus === createIsInProgress
|| event.ResourceStatus === deleteIsInProgress);
});

// set the date some time before the first found
// stack event of recently issued stack modification
if (firstRelevantEvent) {
const eventDate = new Date(firstRelevantEvent.Timestamp);
const updatedDate = eventDate.setSeconds(eventDate.getSeconds() - 5);
monitoredSince = new Date(updatedDate);
}

// Loop through stack events
data.StackEvents.reverse().forEach((event) => {
const eventInRange = (monitoredSince < event.Timestamp);
stackEvents.reverse().forEach((event) => {
const eventInRange = (monitoredSince <= event.Timestamp);
const eventNotLogged = (loggedEvents.indexOf(event.EventId) === -1);
let eventStatus = event.ResourceStatus || null;
if (eventInRange && eventNotLogged) {
Expand Down

0 comments on commit af3d463

Please sign in to comment.