Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix monitor events #62

Merged
merged 7 commits into from
Oct 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}


})();