From fd9132a9d1ebf1bf881291bb2d3a2fc4658791e4 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Thu, 5 Jun 2025 01:27:26 -0700 Subject: [PATCH] removed chron from discord server --- apps/discord-server/index.ts | 1 - apps/discord-server/modules/chron.ts | 62 ---------------------------- 2 files changed, 63 deletions(-) delete mode 100644 apps/discord-server/modules/chron.ts diff --git a/apps/discord-server/index.ts b/apps/discord-server/index.ts index 96a11098..8c089588 100644 --- a/apps/discord-server/index.ts +++ b/apps/discord-server/index.ts @@ -3,7 +3,6 @@ import express from "express"; import { createServer } from "http"; import router from "routes/router"; import cors from "cors"; -import "modules/chron"; const app = express(); const server = createServer(app); diff --git a/apps/discord-server/modules/chron.ts b/apps/discord-server/modules/chron.ts deleted file mode 100644 index f7747c0b..00000000 --- a/apps/discord-server/modules/chron.ts +++ /dev/null @@ -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); - } -});