#5 replace all console.logs with debugger
All checks were successful
DRB Tests / drb_mocha_tests (pull_request) Successful in 32s

This commit is contained in:
Logan Cusano
2024-05-25 23:52:18 -04:00
parent 81a215f048
commit 2ab5a181bd
22 changed files with 192 additions and 133 deletions

View File

@@ -5,6 +5,9 @@ import { DebugBuilder } from "../modules/debugger.mjs";
import UserAgent from "user-agents";
import Parser from 'rss-parser';
import dotenv from 'dotenv';
dotenv.config()
// Initialize the User-Agent string
process.env.USER_AGENT_STRING = new UserAgent({ platform: 'Win32' }).toString();
@@ -16,8 +19,9 @@ const parser = new Parser({
});
const log = new DebugBuilder("server", "feedHandler");
const runningPostsToRemove = {};
const sourceFailureLimit = 5;
const sourceFailureLimit = process.env.RSS_SOURCE_FAILURE_LIMIT ?? 5;
const runningSourcesToRemove = {}; // This holds the sources that are pending removal (they've failed to load, return data, etc.)
export const returnHash = (...stringsIncluded) => {
return crypto.createHash('sha1').update(stringsIncluded.join("-<<??//\\\\??>>-")).digest("base64");
@@ -100,22 +104,22 @@ export const addSource = async (title, link, category, guildId, channelId, callb
export const removeSource = async (sourceURL) => {
log.INFO("Removing source:", sourceURL);
if (!runningPostsToRemove[sourceURL]) {
runningPostsToRemove[sourceURL] = { count: 1, timestamp: Date.now(), ignoredAttempts: 0 };
if (!runningSourcesToRemove[sourceURL]) {
runningSourcesToRemove[sourceURL] = { count: 1, timestamp: Date.now(), ignoredAttempts: 0 };
return;
}
const elapsedTime = Date.now() - runningPostsToRemove[sourceURL].timestamp;
const waitTime = runningPostsToRemove[sourceURL].count * 30000;
const elapsedTime = Date.now() - runningSourcesToRemove[sourceURL].timestamp;
const waitTime = runningSourcesToRemove[sourceURL].count * 30000;
if (elapsedTime <= waitTime) {
runningPostsToRemove[sourceURL].ignoredAttempts += 1;
runningSourcesToRemove[sourceURL].ignoredAttempts += 1;
return;
}
if (runningPostsToRemove[sourceURL].count < sourceFailureLimit) {
runningPostsToRemove[sourceURL].count += 1;
runningPostsToRemove[sourceURL].timestamp = Date.now();
if (runningSourcesToRemove[sourceURL].count < sourceFailureLimit) {
runningSourcesToRemove[sourceURL].count += 1;
runningSourcesToRemove[sourceURL].timestamp = Date.now();
return;
}