#5 replace all console.logs with debugger
All checks were successful
DRB Tests / drb_mocha_tests (pull_request) Successful in 32s
All checks were successful
DRB Tests / drb_mocha_tests (pull_request) Successful in 32s
This commit is contained in:
@@ -1,37 +1,49 @@
|
||||
//Will handle updating feeds in all channels
|
||||
// Will handle updating feeds in all channels
|
||||
|
||||
import { DebugBuilder } from "../modules/debugger.mjs";
|
||||
import { updateFeeds } from "./feedHandler.mjs";
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config()
|
||||
dotenv.config();
|
||||
|
||||
const log = new DebugBuilder("server", "rssController");
|
||||
|
||||
const refreshInterval = process.env.RSS_REFRESH_INTERVAL ?? 300000;
|
||||
const refreshInterval = parseInt(process.env.RSS_REFRESH_INTERVAL) || 300000;
|
||||
|
||||
export class RSSController {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
this.client = client;
|
||||
this.intervalId = null;
|
||||
}
|
||||
|
||||
async start() {
|
||||
// Wait for the refresh period before starting RSS feeds, so the rest of the bot can start
|
||||
await new Promise(resolve => setTimeout(resolve, refreshInterval));
|
||||
|
||||
log.INFO("Starting RSS Controller");
|
||||
// Get initial feeds before starting the infinite loop
|
||||
await updateFeeds(this.client);
|
||||
|
||||
while(true) {
|
||||
// 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));
|
||||
try {
|
||||
log.INFO("Starting RSS Controller");
|
||||
// Get initial feeds before starting the interval loop
|
||||
await this.collectLatestPosts();
|
||||
await new Promise(resolve => setTimeout(resolve, refreshInterval / 4));
|
||||
}
|
||||
|
||||
// Start the interval loop for updating feeds
|
||||
this.intervalId = setInterval(async () => {
|
||||
await this.collectLatestPosts();
|
||||
}, refreshInterval);
|
||||
|
||||
} catch (error) {
|
||||
log.ERROR(`Failed to start RSS Controller: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async stop() {
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId);
|
||||
log.INFO("RSS Controller stopped");
|
||||
}
|
||||
}
|
||||
|
||||
async collectLatestPosts() {
|
||||
log.INFO("Updating sources");
|
||||
await updateFeeds(this.client);
|
||||
try {
|
||||
log.INFO("Updating sources");
|
||||
await updateFeeds(this.client);
|
||||
} catch (error) {
|
||||
log.ERROR(`Error updating feeds: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user