From 3f928d8742c83e6fceb102cd83176139a57628bc Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 17 Jan 2020 12:09:42 +0200 Subject: [PATCH] Check for updates every day --- src/plugins/changelog.js | 21 +++++++++++++++++++++ src/server.js | 12 +----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/plugins/changelog.js b/src/plugins/changelog.js index df474365..9c717430 100644 --- a/src/plugins/changelog.js +++ b/src/plugins/changelog.js @@ -1,6 +1,7 @@ "use strict"; const got = require("got"); +const colors = require("chalk"); const log = require("../log"); const pkg = require("../../package.json"); @@ -9,6 +10,7 @@ const TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes, in milliseconds module.exports = { isUpdateAvailable: false, fetch, + checkForUpdates, }; 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}` + ); + }); +} diff --git a/src/server.js b/src/server.js index 904a0995..4c771f8d 100644 --- a/src/server.js +++ b/src/server.js @@ -241,17 +241,7 @@ module.exports = function(options = {}) { } }); - changelog.fetch().then((versionData) => { - if (!versionData.latest) { - return; - } - - log.info( - `The Lounge ${colors.green( - versionData.latest.version - )} is available. Read more on GitHub: ${versionData.latest.url}` - ); - }); + changelog.checkForUpdates(); return server; };