Add waits and extra sleeps to slow down the rss engine

This commit is contained in:
Logan Cusano
2023-03-11 16:53:07 -05:00
parent a64fe6a669
commit 81851a11b7

View File

@@ -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;
}
}