Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lielran
Created March 8, 2019 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lielran/31c8e2b7f940539585c9f7b913affa7a to your computer and use it in GitHub Desktop.
Save lielran/31c8e2b7f940539585c9f7b913affa7a to your computer and use it in GitHub Desktop.
AsyncServerlessPlugin
'use strict';
const BbPromise = require('bluebird');
class ServerlessPlugin {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.log = this.serverless.cli.log.bind(this);
this.commands = {};
this.hooks = {
'after:deploy:deploy': () => BbPromise.bind(this)
.then(this.pluginAsyncAction)
}
}
pluginAsyncAction() {
this.serverless.cli.log('before deploy hook');
let promise = BbPromise.fromCallback(cb => {
setTimeout(() => {
this.serverless.cli.log('async logic') // Simultate Async action. block next hook and runs after `after deploy hook` print
cb();
}, 4000);
});
this.serverless.cli.log('after deploy hook');
return promise;
}
}
module.exports = ServerlessPlugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment