From 81851a11b7a32a1e0a0a24d5faee122feb9e13fe Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sat, 11 Mar 2023 16:53:07 -0500 Subject: [PATCH] Add waits and extra sleeps to slow down the rss engine --- controllers/rssController.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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; } }