Sekundäreinsatz wird nun richtig angezeigt

This commit is contained in:
PxlLoewe
2025-06-17 22:06:04 -07:00
parent edfd0c9e30
commit 72c6d53c05
8 changed files with 67 additions and 17 deletions

View File

@@ -52,10 +52,31 @@ const removeClosedMissions = async () => {
console.log(`Mission ${mission.id} closed due to inactivity.`);
});
};
const removeConnectedAircrafts = async () => {
const connectedAircrafts = await prisma.connectedAircraft.findMany({
where: {
logoutTime: null,
},
});
connectedAircrafts.forEach(async (aircraft) => {
const lastUpdate = new Date(aircraft.lastHeartbeat);
const now = new Date();
if (now.getTime() - lastUpdate.getTime() > 12 * 60 * 60 * 1000) {
await prisma.connectedAircraft.update({
where: { id: aircraft.id },
data: { logoutTime: now },
});
console.log(`Aircraft ${aircraft.id} disconnected due to inactivity.`);
}
});
};
cron.schedule("*/5 * * * *", async () => {
try {
await removeClosedMissions();
await removeConnectedAircrafts();
} catch (error) {
console.error("Error removing closed missions:", error);
}