refactor(CLI): Change stack update progress logging method

This commit is contained in:
Mariusz Nowak 2021-10-07 10:20:44 +02:00 committed by Mariusz Nowak
parent 7c91cde7ac
commit 8184c01c7c

View File

@ -7,7 +7,6 @@ const identity = require('ext/function/identity');
const ServerlessError = require('../../../serverless-error');
const { log, legacy, progress, style } = require('@serverless/utils/log');
const mainProgress = progress.get('main');
const validStatuses = new Set(['CREATE_COMPLETE', 'UPDATE_COMPLETE', 'DELETE_COMPLETE']);
const normalizerPattern = /(?<!^)([A-Z])/g;
@ -27,14 +26,7 @@ module.exports = {
cfData,
stackUrl,
options,
{
loggedEventIds = new Set(),
stackStatus = null,
stackLatestError = null,
firstEventId = null,
inProgressResources = new Set(),
completedResources = new Set(),
}
{ loggedEventIds = new Set(), stackStatus = null, stackLatestError = null, firstEventId = null }
) {
return wait(options.frequency || process.env.SLS_AWS_MONITORING_FREQUENCY || 5000)
.then(() =>
@ -99,27 +91,20 @@ module.exports = {
legacy.write(chalk.yellow('.'));
}
if (event.ResourceType !== 'AWS::CloudFormation::Stack') {
if (action !== 'create' && event.ResourceType !== 'AWS::CloudFormation::Stack') {
if (eventStatus && eventStatus.endsWith('PROGRESS')) {
inProgressResources.add(event.LogicalResourceId);
progress
.get(`cf-deploy-${event.LogicalResourceId}`)
.notice(
style.aside(
` ${eventStatus} - ${event.ResourceType} - ${event.LogicalResourceId}`
)
);
} else if (eventStatus && eventStatus.endsWith('COMPLETE')) {
completedResources.add(event.LogicalResourceId);
inProgressResources.delete(event.LogicalResourceId);
progress.get(`cf-deploy-${event.LogicalResourceId}`).remove();
}
}
if ((completedResources.size || inProgressResources.size) && action !== 'create') {
const progressMessagePrefix = (() => {
if (action === 'update') return 'Updating';
if (action === 'delete') return 'Removing';
throw new Error(`Unrecgonized action: ${action}`);
})();
mainProgress.notice(
`${progressMessagePrefix} CloudFormation stack (${completedResources.size}/${
completedResources.size + inProgressResources.size
})`
);
}
// Prepare for next monitoring action
loggedEventIds.add(event.EventId);
});
@ -184,8 +169,6 @@ module.exports = {
stackStatus,
stackLatestError,
firstEventId,
inProgressResources,
completedResources,
});
});
},