Files
drb-server/rss-manager/rssController.mjs
Logan Cusano 2ab5a181bd
All checks were successful
DRB Tests / drb_mocha_tests (pull_request) Successful in 32s
#5 replace all console.logs with debugger
2024-05-25 23:52:18 -04:00

50 lines
1.3 KiB
JavaScript

// Will handle updating feeds in all channels
import { DebugBuilder } from "../modules/debugger.mjs";
import { updateFeeds } from "./feedHandler.mjs";
import dotenv from 'dotenv';
dotenv.config();
const log = new DebugBuilder("server", "rssController");
const refreshInterval = parseInt(process.env.RSS_REFRESH_INTERVAL) || 300000;
export class RSSController {
constructor(client) {
this.client = client;
this.intervalId = null;
}
async start() {
try {
log.INFO("Starting RSS Controller");
// Get initial feeds before starting the interval loop
await this.collectLatestPosts();
// 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() {
try {
log.INFO("Updating sources");
await updateFeeds(this.client);
} catch (error) {
log.ERROR(`Error updating feeds: ${error.message}`);
}
}
}