added more restrictions to mission cleanup
This commit is contained in:
@@ -13,30 +13,43 @@ const removeClosedMissions = async () => {
|
||||
});
|
||||
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 (lastAlertTime && now.getTime() - lastAlertTime.getTime() > 180 * 60 * 1000) {
|
||||
const log: MissionLog = {
|
||||
type: "completed-log",
|
||||
auto: true,
|
||||
timeStamp: new Date().toISOString(),
|
||||
data: {},
|
||||
};
|
||||
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,
|
||||
await prisma.mission.update({
|
||||
where: {
|
||||
id: mission.id,
|
||||
},
|
||||
data: {
|
||||
state: "finished",
|
||||
missionLog: {
|
||||
push: log as any,
|
||||
},
|
||||
data: {
|
||||
state: "finished",
|
||||
missionLog: {
|
||||
push: log as any,
|
||||
},
|
||||
},
|
||||
});
|
||||
console.log(`Mission ${mission.id} closed due to inactivity.`);
|
||||
}
|
||||
},
|
||||
});
|
||||
console.log(`Mission ${mission.id} closed due to inactivity.`);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user