Skip to content

Commit

Permalink
refactor(CLI): Modern logs for rollback function command
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 7, 2021
1 parent f0970e0 commit 4cbc342
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/plugins/aws/rollbackFunction.js
Expand Up @@ -4,6 +4,9 @@ const BbPromise = require('bluebird');
const ServerlessError = require('../../serverless-error');
const validate = require('./lib/validate');
const fetch = require('node-fetch');
const { style, log, progress, legacy } = require('@serverless/utils/log');

const mainProgress = progress.get('main');

class AwsRollbackFunction {
constructor(serverless, options) {
Expand All @@ -30,7 +33,12 @@ class AwsRollbackFunction {
// versions need to be string so that AWS understands it
funcVersion = String(this.options['function-version']);

this.serverless.cli.log(`Rolling back function "${funcName}" to version "${funcVersion}"...`);
legacy.log(`Rolling back function "${funcName}" to version "${funcVersion}"...`);
log.notice();
log.notice(`Rolling back function ${funcName} to version "${funcVersion}"`);
log.info(); // Ensure gap between verbose logging

mainProgress.notice('Updating', { isMainEvent: true });

const funcObj = this.serverless.service.getFunction(funcName);

Expand Down Expand Up @@ -68,7 +76,7 @@ class AwsRollbackFunction {
async restoreFunction(zipBuffer) {
const funcName = this.options.function;

this.serverless.cli.log('Restoring function...');
legacy.log('Restoring function...');

const funcObj = this.serverless.service.getFunction(funcName);

Expand All @@ -78,7 +86,17 @@ class AwsRollbackFunction {
};

return this.provider.request('Lambda', 'updateFunctionCode', params).then(() => {
this.serverless.cli.log(`Successfully rolled back function "${this.options.function}"`);
log.notice();
log.notice.success(
`Successfully rolled back function ${funcName} to version "${
this.options['function-version']
}" ${style.aside(
`(${Math.floor(
(Date.now() - this.serverless.pluginManager.commandRunStartTime) / 1000
)}s)`
)}`
);
legacy.log(`Successfully rolled back function "${this.options.function}"`);
});
}
}
Expand Down

0 comments on commit 4cbc342

Please sign in to comment.