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

shortstop-handlers exec, access config value in handler #460

Open
tomalex0 opened this issue May 12, 2016 · 2 comments
Open

shortstop-handlers exec, access config value in handler #460

tomalex0 opened this issue May 12, 2016 · 2 comments
Projects

Comments

@tomalex0
Copy link
Contributor

tomalex0 commented May 12, 2016

I'm looking for an option to get config value in exec handler function, below one i tried but

exec:./lib/utility#getStatus get triggered first and config value will be undefined and might be the expected behavior , is there any alternative approach?

First i was looking into option like this #316 . For this i need to write custom shortstop handler and not sure how to do that in existing kraken setup.

Please let me know if you have any suggestions or solution .

config.json

{
"check" : "exec:./lib/utility#getStatus",
}

utility.js

var settings;

module.exports.init = function (config) {
    settings = config;
}

module.exports.getStatus = function () {


    //How to get config here? console.log(settings);  as of now this is undefined

    return true;
};

spec.js

module.exports = function spec() {

    return {
        /**
         *
         * @param config
         * @param next
         */
        onconfig: function(config, next) {
            //Initiate Utility Function with config
            require('./utility').init(config);

            next(null, config);

        }
    };
};
@jonathansamines
Copy link

Hey @tomalex0 you could just export a function, which returns the getStatus function as an object, which would have access to the config object. Would be something like:

utility.js

  module.exports = (config) => {
     return {
        getStatus() {
           // at this point I have access to the "config" object
            return true;
        }
     };
  };

spec.js

module.exports = function spec() {
    return {
        /**
         *
         * @param config
         * @param next
         */
        onconfig: function(config, next) {
            //Initiate Utility Function with config
            const util = require('./utility')(config);

           var status = util.getStatus(); // true

           // at this point you could also merge the resulting value from `util.getStatus` to the current kraken configuration by calling config.use({ status });

            next(null, config);
        }
    };
};

@tomalex0
Copy link
Contributor Author

@jonathansamines thanks for the response, let me give this a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Triage
Doing
Development

No branches or pull requests

2 participants