diff --git a/controllers/rssController.js b/controllers/rssController.js index c8e31f2..6fe2b7f 100644 --- a/controllers/rssController.js +++ b/controllers/rssController.js @@ -6,7 +6,7 @@ const log = new DebugBuilder("server", "rssController"); const libCore = require("../libCore"); const libUtils = require("../libUtils"); -const timeoutValue = process.env.RSS_TIMEOUT_VALUE ?? 300000; +const refreshInterval = process.env.RSS_REFRESH_INTERVAL ?? 300000; exports.RSSController = class RSSController { constructor(_client) { @@ -14,19 +14,25 @@ exports.RSSController = class RSSController { } async start(){ - // Wait 30 seconds for the rest of the bot to start before starting rss feeds + // Wait 30 seconds for the rest of the bot to start before starting rss feeds await new Promise(resolve => setTimeout(resolve, 30000)); + log.INFO("Starting RSS Controller"); + // Get initial feeds before the starting the infinite loop await libCore.updateFeeds(this.client); + while(true){ - await new Promise(resolve => setTimeout(resolve, timeoutValue)); - this.collectLatestPosts(); + // Wait for the refresh interval, then wait for the posts to return, then wait a quarter of the refresh interval to make sure everything is cleared up + await new Promise(resolve => setTimeout(resolve, refreshInterval)); + await this.collectLatestPosts(); + await new Promise(resolve => setTimeout(resolve, refreshInterval / 4)); + continue; } } async collectLatestPosts(){ log.INFO("Updating sources"); - libCore.updateFeeds(this.client) + await libCore.updateFeeds(this.client) return; } }