Skip to content

Commit

Permalink
fix monitor events (#62)
Browse files Browse the repository at this point in the history
* Add missing next token reference

* Ensure to add the child stacks

* Update error states to include rollback

* Avoid missing latest status

* Update spinner to run faster

* Move print output to function

* Remove spinner delay
  • Loading branch information
facundovictor authored and rpigu-i committed Oct 10, 2018
1 parent d4796f4 commit 05e2aac
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions bin/capsule.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const error_states = [
'DELETE_FAILED',
'UPDATE_FAILED',
'ROLLBACK_FAILED',
'UPDATE_ROLLBACK_FAILED'
'UPDATE_ROLLBACK_FAILED',
'UPDATE_ROLLBACK_IN_PROGRESS',
'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS'
];

const paths = {
Expand Down Expand Up @@ -417,12 +419,12 @@ const getStackEventColor = (state) => {
*
* @return {String} output_line
*/
const getStackEventOutputLine = (e) => {
const printStackEventOutputLine = (e) => {
let time = `${e.Timestamp.toLocaleString()}`;
let status = `${chalk[getStackEventColor(e.ResourceStatus)](e.ResourceStatus)}`;
let resource = `${e.ResourceType}`;
let id = `${e.PhysicalResourceId}`;
return `${time} ${status} ${resource} ${id}`;
console.log(`${time} ${status} ${resource} ${id}`);
}

/**
Expand Down Expand Up @@ -629,15 +631,19 @@ const getNextStackEvent = async (id, next) => {
const getStackEvents = async (id) => {
let response = await getNextStackEvent(id);
let events = response.StackEvents;

while (typeof response.NextToken !== 'undefined') {
response = await getNextStackEvent(id);
response = await getNextStackEvent(id, response.NextToken);
events.concat(response.StackEvents);
}

let nestedStackIds = events.reduce((list, e) => {
let physical_resource_id = e.PhysicalResourceId;
if (e.ResourceType === 'AWS::CloudFormation::Stack' &&
e.PhysicalResourceId != '' && e.StackId != e.PhysicalResourceId) {
list.push(e.StackId);
physical_resource_id != '' &&
e.StackId != physical_resource_id &&
!list.includes(physical_resource_id)) {
list.push(physical_resource_id);
}
return list;
}, []);
Expand Down Expand Up @@ -689,10 +695,7 @@ const monitorStackProgress = async (id, token) => {
logIfVerbose(`Event ignored: ${e.EventId}`);
} else {
logIfVerbose(`NEW Event: ${e}`);
spinner.text = getStackEventOutputLine(e);
if (e.ResourceStatusReason !== 'User Initiated') {
process.stdout.write('\n');
}
printStackEventOutputLine(e);
events_seen.push(e.EventId);
}
if (e.ResourceType === 'AWS::CloudFormation::Stack' &&
Expand All @@ -705,11 +708,10 @@ const monitorStackProgress = async (id, token) => {
}
last_time = e.Timestamp;
}
if (in_progress) {
await delay(1000);
}
await delay(1000);
}
spinner.stop();
process.stdout.write('\n');
logIfVerbose(`End monitoring stack ${id} with token ${token}`);
}

Expand Down Expand Up @@ -1321,5 +1323,4 @@ const processConfiguration = async () => {
await ciCmds(type)
}


})();

0 comments on commit 05e2aac

Please sign in to comment.