Skip to content

Commit

Permalink
Export updater.stop_checking() so that we can cancel the one-hour int…
Browse files Browse the repository at this point in the history
…erval check for new releases.
  • Loading branch information
tomas committed Dec 29, 2014
1 parent 40baf40 commit 19607b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/agent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var boot = function() {
commands.start_watching(); // add/remove from list when started or stopped

if (config.get('auto_update'))
updater.keep_checking(); // check every one hour for new releases
updater.check_every(60 * 60 * 1000); // check every one hour for new releases

logger.info('Initialized.');
});
Expand Down Expand Up @@ -223,6 +223,7 @@ var shutdown = function(cb) {

running = false;
commands.stop_watching();
updater.stop_checking();

logger.debug('Unloading plugins.');
unload_plugins(cb);
Expand Down
12 changes: 10 additions & 2 deletions lib/agent/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var join = require('path').join,
system = common.system,
child_process = require('child_process'); // need to use child_process for stubbing to work in test

var timer; // for interval check

var no_versions_support_error = function() {
var err = new Error('No versions support.');
err.code = 'NO_VERSIONS_SUPPORT';
Expand Down Expand Up @@ -105,9 +107,15 @@ exports.check = function(cb){
check_for_update(cb);
};

exports.keep_checking = function(cb) {
exports.check_every = function(interval, cb) {
if (!system.paths.versions)
return cb && cb(no_versions_support_error());

setInterval(check_for_update, 60 * 60 * 1000); // check every one hour
var interval = interval || 60 * 60 * 1000; // one hour by default
timer = setInterval(check_for_update, interval);
}

exports.stop_checking = function() {
if (timer) clearInterval(timer);
timer = null;
}

0 comments on commit 19607b8

Please sign in to comment.