removed chron from discord server

This commit is contained in:
PxlLoewe
2025-06-05 01:27:26 -07:00
parent 97e2d437b4
commit fd9132a9d1
2 changed files with 0 additions and 63 deletions

View File

@@ -3,7 +3,6 @@ import express from "express";
import { createServer } from "http"; import { createServer } from "http";
import router from "routes/router"; import router from "routes/router";
import cors from "cors"; import cors from "cors";
import "modules/chron";
const app = express(); const app = express();
const server = createServer(app); const server = createServer(app);

View File

@@ -1,62 +0,0 @@
import { MissionLog, prisma } from "@repo/db";
import cron from "node-cron";
const removeClosedMissions = async () => {
const oldMissions = await prisma.mission.findMany({
where: {
state: "running",
},
});
oldMissions.forEach(async (mission) => {
const lastAlert = (mission.missionLog as unknown as MissionLog[]).find((l) => {
return l.type === "alert-log";
});
const lastAlertTime = lastAlert ? new Date(lastAlert.timeStamp) : null;
const aircraftsInMission = await prisma.connectedAircraft.findMany({
where: {
stationId: {
in: mission.missionStationIds,
},
},
});
if (
!aircraftsInMission ||
!aircraftsInMission.some((a) => ["1", "2", "6"].includes(a.fmsStatus))
)
return;
const now = new Date();
if (!lastAlertTime) return;
// change State to closed if last alert was more than 180 minutes ago
if (now.getTime() - lastAlertTime.getTime() < 30 * 60 * 1000) return;
const log: MissionLog = {
type: "completed-log",
auto: true,
timeStamp: new Date().toISOString(),
data: {},
};
await prisma.mission.update({
where: {
id: mission.id,
},
data: {
state: "finished",
missionLog: {
push: log as any,
},
},
});
console.log(`Mission ${mission.id} closed due to inactivity.`);
});
};
cron.schedule("*/5 * * * *", async () => {
try {
await removeClosedMissions();
} catch (error) {
console.error("Error removing closed missions:", error);
}
});