add website tracking
All checks were successful
deploy / deploy (push) Successful in 22s
Publish Docker Image / docker (push) Successful in 46s

This commit is contained in:
Lee
2024-01-04 00:57:21 +00:00
parent 358bb6272c
commit ff11240334
7 changed files with 195 additions and 3 deletions

View File

@ -0,0 +1,47 @@
import cron from "node-cron";
import { logger } from "../utils/logger";
import Config from "../../data/config.json";
import Websites from "../../data/websites.json";
import Website from "./website";
export default class WebsiteManager {
private websites: Website[] = [];
constructor() {
logger.info("Loading websites...");
for (const configWebsite of Websites) {
const website = new Website({
name: configWebsite.name,
url: configWebsite.url,
});
this.websites.push(website);
}
logger.info(`Loaded ${this.websites.length} websites!`);
cron.schedule(Config.pinger.pingCron, () => {
this.pingWebsites();
});
}
/**
* Ping all websites to update their status.
*/
private async pingWebsites(): Promise<void> {
logger.info(`Pinging websites ${this.websites.length}`);
// ping all websites in parallel
await Promise.all(this.websites.map((website) => website.pingWebsite()));
logger.info("Finished pinging websites!");
}
/**
* Returns the websites.
*
* @returns the websites
*/
public getWebsites(): Website[] {
return this.websites;
}
}