From 19607b8a374572c0795ad80a7ef37edc599c80ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Pollak?= Date: Mon, 29 Dec 2014 18:47:09 -0300 Subject: [PATCH] Export updater.stop_checking() so that we can cancel the one-hour interval check for new releases. --- lib/agent/index.js | 3 ++- lib/agent/updater.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/agent/index.js b/lib/agent/index.js index 8ff9f61ab..a95d9ba4c 100644 --- a/lib/agent/index.js +++ b/lib/agent/index.js @@ -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.'); }); @@ -223,6 +223,7 @@ var shutdown = function(cb) { running = false; commands.stop_watching(); + updater.stop_checking(); logger.debug('Unloading plugins.'); unload_plugins(cb); diff --git a/lib/agent/updater.js b/lib/agent/updater.js index 60023531a..72632c349 100644 --- a/lib/agent/updater.js +++ b/lib/agent/updater.js @@ -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'; @@ -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; +} \ No newline at end of file