Check for updates every day

This commit is contained in:
Pavel Djundik 2020-01-17 12:09:42 +02:00
parent efc421c0a6
commit 3f928d8742
2 changed files with 22 additions and 11 deletions

View File

@ -1,6 +1,7 @@
"use strict"; "use strict";
const got = require("got"); const got = require("got");
const colors = require("chalk");
const log = require("../log"); const log = require("../log");
const pkg = require("../../package.json"); const pkg = require("../../package.json");
@ -9,6 +10,7 @@ const TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes, in milliseconds
module.exports = { module.exports = {
isUpdateAvailable: false, isUpdateAvailable: false,
fetch, fetch,
checkForUpdates,
}; };
const versions = { const versions = {
@ -87,3 +89,22 @@ function updateVersions(response) {
} }
} }
} }
function checkForUpdates() {
fetch().then((versionData) => {
if (!module.exports.isUpdateAvailable) {
// Check for updates every 24 hours + random jitter of <3 hours
setTimeout(checkForUpdates, 24 * 3600 * 1000 + Math.floor(Math.random() * 10000000));
}
if (!versionData.latest) {
return;
}
log.info(
`The Lounge ${colors.green(
versionData.latest.version
)} is available. Read more on GitHub: ${versionData.latest.url}`
);
});
}

View File

@ -241,17 +241,7 @@ module.exports = function(options = {}) {
} }
}); });
changelog.fetch().then((versionData) => { changelog.checkForUpdates();
if (!versionData.latest) {
return;
}
log.info(
`The Lounge ${colors.green(
versionData.latest.version
)} is available. Read more on GitHub: ${versionData.latest.url}`
);
});
return server; return server;
}; };