Skip to content

Commit 11f19ac

Browse files
committed
Passing options object to loadCommands instead of bool
1 parent a4ff441 commit 11f19ac

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

Diff for: scripts/stackstorm.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ module.exports = function(robot) {
175175
robot.logger.error('Failed to authenticate: ' + err.message);
176176

177177
if (env.EXIT_ON_FAILURES) {
178-
stop({exit: true});
178+
stop({exitOnFailure: true});
179179
} else {
180180
throw err;
181181
}
@@ -206,9 +206,11 @@ module.exports = function(robot) {
206206
// handler to manage per adapter message post-ing.
207207
var postDataHandler = postData.getDataPostHandler(robot.adapterName, robot, formatter);
208208

209-
var loadCommands = function(exitOnFailure) {
209+
var loadCommands = function(exitOpts) {
210210
robot.logger.info('Loading commands....');
211211

212+
var exitOpts = _.merge({}, {exitOnFailure: false }, exitOpts)
213+
212214
api.actionAlias.list()
213215
.then(function (aliases) {
214216
// Remove all the existing commands
@@ -245,8 +247,8 @@ module.exports = function(robot) {
245247
.catch(function (err) {
246248
var error_msg = 'Failed to retrieve commands from "%s": %s';
247249
robot.logger.error(util.format(error_msg, env.ST2_API_URL, err.message));
248-
if (exitOnFailure) {
249-
stop({exit: true});
250+
if (exitOpts.exitOnFailure) {
251+
stop(exitOpts);
250252
}
251253
});
252254
};
@@ -420,30 +422,30 @@ module.exports = function(robot) {
420422
});
421423

422424
// Initial command loading
423-
loadCommands(env.EXIT_ON_FAILURES);
425+
loadCommands({exitOnFailure: env.EXIT_ON_FAILURES});
426+
427+
// Add an interval which tries to re-load the commands
428+
commands_load_interval = setInterval(loadCommands.bind(), (env.ST2_COMMANDS_RELOAD_INTERVAL * 1000));
424429

425430
// Install SIGUSR2 handler which reloads the command
426431
install_sigusr2_handler();
427-
428-
// Add an interval which tries to re-load the commands
429-
commands_load_interval = setInterval(loadCommands.bind(self, false), (env.ST2_COMMANDS_RELOAD_INTERVAL * 1000));
430432
}
431433

432-
function stop(exitFromProcess) {
434+
function stop(exitOpts) {
433435
clearInterval(commands_load_interval);
434436
api.stream.listen().then(function (source) {
435437
source.removeAllListeners();
436438
source.close();
437439
});
438440

439-
if (exitFromProcess.exit) {
441+
if (exitOpts.exitOnFailure) {
440442
process.exit(1)
441443
}
442444
}
443445

444446
function install_sigusr2_handler() {
445447
process.on('SIGUSR2', function() {
446-
loadCommands(false);
448+
loadCommands();
447449
});
448450
}
449451

0 commit comments

Comments
 (0)