unify update check into a single job
This commit is contained in:
17
src/cron.js
17
src/cron.js
@@ -40,9 +40,8 @@ var appHealthMonitor = require('./apphealthmonitor.js'),
|
||||
var gJobs = {
|
||||
appAutoUpdater: null,
|
||||
boxAutoUpdater: null,
|
||||
appUpdateChecker: null,
|
||||
backup: null,
|
||||
boxUpdateChecker: null,
|
||||
updateChecker: null,
|
||||
systemChecks: null,
|
||||
diskSpaceChecker: null,
|
||||
certificateRenew: null,
|
||||
@@ -68,7 +67,7 @@ var NOOP_CALLBACK = function (error) { if (error) debug(error); };
|
||||
function startJobs(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
const randomMinute = Math.floor(60*Math.random());
|
||||
const randomTick = Math.floor(60*Math.random());
|
||||
gJobs.systemChecks = new CronJob({
|
||||
cronTime: '00 30 2 * * *', // once a day. if you change this interval, change the notification messages with correct duration
|
||||
onTick: () => cloudron.runSystemChecks(NOOP_CALLBACK),
|
||||
@@ -81,16 +80,10 @@ function startJobs(callback) {
|
||||
start: true
|
||||
});
|
||||
|
||||
gJobs.boxUpdateCheckerJob = new CronJob({
|
||||
cronTime: '00 ' + randomMinute + ' 1,3,5,21,23 * * *', // 5 times
|
||||
onTick: () => updateChecker.checkBoxUpdates({ automatic: true }, NOOP_CALLBACK),
|
||||
start: true
|
||||
});
|
||||
|
||||
// this is run separately from the update itself so that the user can disable automatic updates but can still get a notification
|
||||
gJobs.appUpdateChecker = new CronJob({
|
||||
cronTime: '00 ' + randomMinute + ' 2,4,6,20,22 * * *', // 5 times
|
||||
onTick: () => updateChecker.checkAppUpdates({ automatic: true }, NOOP_CALLBACK),
|
||||
gJobs.updateCheckerJob = new CronJob({
|
||||
cronTime: `${randomTick} ${randomTick} 1,5,9,13,17,21,23 * * *`,
|
||||
onTick: () => updateChecker.checkForUpdates({ automatic: true }, NOOP_CALLBACK),
|
||||
start: true
|
||||
});
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ exports = module.exports = {
|
||||
};
|
||||
|
||||
let assert = require('assert'),
|
||||
async = require('async'),
|
||||
auditSource = require('../auditsource.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
cloudron = require('../cloudron.js'),
|
||||
@@ -204,10 +203,7 @@ function checkForUpdates(req, res, next) {
|
||||
// it can take a while sometimes to get all the app updates one by one
|
||||
req.clearTimeout();
|
||||
|
||||
async.series([
|
||||
(done) => updateChecker.checkAppUpdates({ automatic: false }, done),
|
||||
(done) => updateChecker.checkBoxUpdates({ automatic: false }, done),
|
||||
], function () {
|
||||
updateChecker.checkForUpdates({ automatic: false }, function () {
|
||||
next(new HttpSuccess(200, { update: updateChecker.getUpdateInfo() }));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('updatechecker - box - manual (email)', function () {
|
||||
.query({ boxVersion: constants.VERSION, accessToken: 'atoken', automatic: false })
|
||||
.reply(204, { } );
|
||||
|
||||
updatechecker.checkBoxUpdates({ automatic: false }, function (error) {
|
||||
updatechecker.checkForUpdates({ automatic: false }, function (error) {
|
||||
expect(!error).to.be.ok();
|
||||
expect(updatechecker.getUpdateInfo().box).to.be(null);
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
@@ -114,7 +114,7 @@ describe('updatechecker - box - manual (email)', function () {
|
||||
.query({ boxVersion: constants.VERSION, accessToken: 'atoken', automatic: false })
|
||||
.reply(200, { version: UPDATE_VERSION, changelog: [''], sourceTarballUrl: 'box.tar.gz', sourceTarballSigUrl: 'box.tar.gz.sig', boxVersionsUrl: 'box.versions', boxVersionsSigUrl: 'box.versions.sig' } );
|
||||
|
||||
updatechecker.checkBoxUpdates({ automatic: false }, function (error) {
|
||||
updatechecker.checkForUpdates({ automatic: false }, function (error) {
|
||||
expect(!error).to.be.ok();
|
||||
expect(updatechecker.getUpdateInfo().box.version).to.be(UPDATE_VERSION);
|
||||
expect(updatechecker.getUpdateInfo().box.sourceTarballUrl).to.be('box.tar.gz');
|
||||
@@ -132,7 +132,7 @@ describe('updatechecker - box - manual (email)', function () {
|
||||
.query({ boxVersion: constants.VERSION, accessToken: 'atoken', automatic: false })
|
||||
.reply(404, { version: '2.0.0-pre.0', changelog: [''], sourceTarballUrl: 'box-pre.tar.gz' } );
|
||||
|
||||
updatechecker.checkBoxUpdates({ automatic: false }, function (error) {
|
||||
updatechecker.checkForUpdates({ automatic: false }, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
expect(updatechecker.getUpdateInfo().box).to.be(null);
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
@@ -167,7 +167,7 @@ describe('updatechecker - box - automatic (no email)', function () {
|
||||
.query({ boxVersion: constants.VERSION, accessToken: 'atoken', automatic: false })
|
||||
.reply(200, { version: UPDATE_VERSION, changelog: [''], sourceTarballUrl: 'box.tar.gz', sourceTarballSigUrl: 'box.tar.gz.sig', boxVersionsUrl: 'box.versions', boxVersionsSigUrl: 'box.versions.sig' } );
|
||||
|
||||
updatechecker.checkBoxUpdates({ automatic: false }, function (error) {
|
||||
updatechecker.checkForUpdates({ automatic: false }, function (error) {
|
||||
expect(!error).to.be.ok();
|
||||
expect(updatechecker.getUpdateInfo().box.version).to.be(UPDATE_VERSION);
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
@@ -202,7 +202,7 @@ describe('updatechecker - box - automatic free (email)', function () {
|
||||
.query({ boxVersion: constants.VERSION, accessToken: 'atoken', automatic: false })
|
||||
.reply(200, { version: UPDATE_VERSION, changelog: [''], sourceTarballUrl: 'box.tar.gz', sourceTarballSigUrl: 'box.tar.gz.sig', boxVersionsUrl: 'box.versions', boxVersionsSigUrl: 'box.versions.sig' } );
|
||||
|
||||
updatechecker.checkBoxUpdates({ automatic: false }, function (error) {
|
||||
updatechecker.checkForUpdates({ automatic: false }, function (error) {
|
||||
expect(!error).to.be.ok();
|
||||
expect(updatechecker.getUpdateInfo().box.version).to.be(UPDATE_VERSION);
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
checkAppUpdates: checkAppUpdates,
|
||||
checkBoxUpdates: checkBoxUpdates,
|
||||
checkForUpdates,
|
||||
|
||||
getUpdateInfo: getUpdateInfo,
|
||||
resetUpdateInfo: resetUpdateInfo,
|
||||
resetAppUpdateInfo: resetAppUpdateInfo,
|
||||
getUpdateInfo,
|
||||
resetUpdateInfo,
|
||||
resetAppUpdateInfo,
|
||||
|
||||
_setUpdateInfo: setUpdateInfo
|
||||
};
|
||||
@@ -171,3 +170,19 @@ function checkBoxUpdates(options, callback) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function checkForUpdates(options, callback) {
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
checkBoxUpdates(options, function (error) {
|
||||
if (error) debug('checkForUpdates: error checking for box updates:', error);
|
||||
|
||||
checkAppUpdates(options, function (error) {
|
||||
if (error) debug('checkForUpdates: error checking for app updates:', error);
|
||||
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user