#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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user