Plugin for Serverless Framework - Hooks not working properly

I developed a new serverless plugin using hooks to enable following features:

  • Hit the jenkins rest api to stop some service before lambda deployment using before keyword in hook.

  • Hit the jenkins rest api to start the same service after lambda deployment using after keyword in hook.

But it is showing unusual behaviour. i.e sometime it execute the 1st step and then 2nd which is correct. But along with that sometimes it execute the 2nd step first and then the 1st step.
Below is my code snippet:

'use strict';

const BbPromise = require('bluebird');
var request = require('request');

class MyPlugin {
    constructor(serverless, options) {
        this.serverless = serverless;
        this.options = options;
        this.lambdaFunctionName = options['stage'] + '-' + serverless['service']['custom']['lambdaFunctionName'];
        this.hooks = {
            'before:package:initialize': this.beforeDeploy.bind(this),
            'after:package:initialize': this.afterDeploy.bind(this),
        };
        if (this.options.stage === 'dev') {
            this.jenkinsUrl = 'dev-jenkins-url';
            this.authorization = 'dev-jenkins-token';
        } else {
            this.jenkinsUrl = 'prod-jenkins-url';
            this.authorization = 'prod-jenkins-token';
        }
    }

    beforeDeploy() {
        // stop some service
        console.log('before deploy');
        const payload = {
            url: this.jenkinsUrl,
            headers: {
                'Content-Type': 'application/json',
                'Authorization': this.authorization,
            },
            form: {
                json: '{"parameter":[{"name":"CONNECTOR","value":"aws_lambda"},{"name":"ENV","value":"' + this.options['stage'] + '"},{"name":"ACTION","value":"stop"},{"name":"REGION","value":"' + this.options['region'] + '"},{"name":"USER","value":"vikki_kr_ch"},{"name":"LAMBDA_FUNCTION_NAME","value":"' + this.lambdaFunctionName + '"}]}}',
            },
        };
        return this.makeRequest(payload)
            .then(body => {
                console.log('before deploy success');
                console.log(body);
            })
            .catch(err => {
                console.log('before deploy err');
                console.log(err);
            });
    }

    afterDeploy() {
        // start the same service
        console.log('after deploy');
        const payload = {
            url: this.jenkinsUrl,
            headers: {
                'Content-Type': 'application/json',
                'Authorization': this.authorization,
            },
            form: {
                json: '',
            },
        };
        return this.makeRequest(payload)
            .then(body => {
                console.log('after deploy success');
                console.log(body);
            })
            .catch(err => {
                console.log('after deploy err');
                console.log(err);
            });
    }
    makeRequest(options) {
        return new BbPromise((resolve, reject) => {
            //      return resolve('Testbody');
            return request.post(options, function(err, httpResponse, body) {
                console.log('statusCode:', httpResponse.statusCode);
                if (err) {
                    reject(err);
                } else {
                    resolve(body);
                }
            });
        });
    }
}

module.exports = MyPlugin;

Thanks,
Vikki