Add waits and extra sleeps to slow down the rss engine
This commit is contained in:
@@ -6,7 +6,7 @@ const log = new DebugBuilder("server", "rssController");
|
|||||||
const libCore = require("../libCore");
|
const libCore = require("../libCore");
|
||||||
const libUtils = require("../libUtils");
|
const libUtils = require("../libUtils");
|
||||||
|
|
||||||
const timeoutValue = process.env.RSS_TIMEOUT_VALUE ?? 300000;
|
const refreshInterval = process.env.RSS_REFRESH_INTERVAL ?? 300000;
|
||||||
|
|
||||||
exports.RSSController = class RSSController {
|
exports.RSSController = class RSSController {
|
||||||
constructor(_client) {
|
constructor(_client) {
|
||||||
@@ -14,19 +14,25 @@ exports.RSSController = class RSSController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async start(){
|
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));
|
await new Promise(resolve => setTimeout(resolve, 30000));
|
||||||
|
|
||||||
log.INFO("Starting RSS Controller");
|
log.INFO("Starting RSS Controller");
|
||||||
|
// Get initial feeds before the starting the infinite loop
|
||||||
await libCore.updateFeeds(this.client);
|
await libCore.updateFeeds(this.client);
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
await new Promise(resolve => setTimeout(resolve, timeoutValue));
|
// 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
|
||||||
this.collectLatestPosts();
|
await new Promise(resolve => setTimeout(resolve, refreshInterval));
|
||||||
|
await this.collectLatestPosts();
|
||||||
|
await new Promise(resolve => setTimeout(resolve, refreshInterval / 4));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async collectLatestPosts(){
|
async collectLatestPosts(){
|
||||||
log.INFO("Updating sources");
|
log.INFO("Updating sources");
|
||||||
libCore.updateFeeds(this.client)
|
await libCore.updateFeeds(this.client)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user