meow
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import cron from "node-cron";
|
||||
import { database, serverManager, websocketServer } from "..";
|
||||
import Server, { ServerStatus } from "../server/server";
|
||||
|
||||
import { serverManager } from "..";
|
||||
import Config from "../../data/config.json";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
@ -22,43 +21,9 @@ export default class Scanner {
|
||||
|
||||
// ping all servers in parallel
|
||||
await Promise.all(
|
||||
serverManager.getServers().map((server) => this.scanServer(server))
|
||||
serverManager.getServers().map((server) => server.pingServer())
|
||||
);
|
||||
|
||||
logger.info("Finished scanning servers");
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans a server and inserts the ping into the database.
|
||||
*
|
||||
* @param server the server to scan
|
||||
* @returns a promise that resolves when the server has been scanned
|
||||
*/
|
||||
async scanServer(server: Server): Promise<void> {
|
||||
//logger.info(`Scanning server ${server.getIP()} - ${server.getType()}`);
|
||||
let response;
|
||||
let online = false;
|
||||
|
||||
try {
|
||||
response = await server.pingServer();
|
||||
if (response == undefined) {
|
||||
return; // Server is offline
|
||||
}
|
||||
online = true;
|
||||
} catch (err) {
|
||||
logger.info(`Failed to ping ${server.getIP()}`, err);
|
||||
websocketServer.sendServerError(server, ServerStatus.OFFLINE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!online || !response) {
|
||||
return; // Server is offline
|
||||
}
|
||||
|
||||
database.insertPing(server, response);
|
||||
const isNewRecord = database.insertRecord(server, response);
|
||||
|
||||
// todo: send all server pings at once
|
||||
websocketServer.sendNewPing(server, response, isNewRecord);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user