fix:everyihtgurg

This commit is contained in:
Saahil 2025-03-27 11:37:23 -04:00
parent d2e146e5cb
commit 7e625f74d0
No known key found for this signature in database
GPG key ID: 8A8B64515254CFC6
2 changed files with 19 additions and 5 deletions

View file

@ -18,6 +18,7 @@ import { cronJobFor15daysofcode } from "./15daysofcode";
import { setupSeverCron } from "./seven39feed";
import { cronJobForRPG } from "./rpgysws";
import { onLoadForLockIn } from "./lockinysws";
import { setupFlightlyCron } from "./flightly";
// import { onLoad } from "./lockinysws";
const cronWithCheckIn = Sentry.cron.instrumentNodeCron(cron);
@ -277,6 +278,8 @@ export function setupOverallCron(app: ModifiedApp) {
setupSeverCron(app);
cronJobForRPG(app);
onLoadForLockIn(app);
setupFlightlyCron(app);
return {
// checkAirtableBoba,
cronWithCheckIn,

View file

@ -1,6 +1,7 @@
import dayjs from "dayjs";
import ms from "ms";
import { ModifiedApp } from "./slackapp";
import { Cron } from "croner";
export interface FlightData {
flight: Flight;
flightPosition: FlightPosition[];
@ -174,7 +175,7 @@ function detectChanges(newData, previousData) {
if (typeof newObj[key] === "object" && newObj[key] !== null) {
compareObjects(oldObj[key] || {}, newObj[key], newPath);
} else if (oldObj[key] !== newObj[key]) {
changes.push(`${newPath}: ${oldObj[key]}${newObj[key]}`);
changes.push(`\`${newPath}\`: \`${oldObj[key]}\`\`${newObj[key]}\``);
}
}
}
@ -192,19 +193,29 @@ function detectChanges(newData, previousData) {
// previousData = newData;
}
export function setupFlightlyCron(app: ModifiedApp) {
new Cron("*/20 * * * *", async () => {
await cronForTrackingData(app);
})
}
export async function cronForTrackingData(app: ModifiedApp) {
const IdsToTrack = app.dbs.flightly.get("flightly-ids");
for (const { flightId, userId } of IdsToTrack) {
for (const { flightIds, userId } of IdsToTrack) {
for(const flightId of flightIds){
const flightD = await getFlightData(flightId);
const changes = await detectChanges(flightD, app.dbs.flightly.get(userId));
const changes = await detectChanges(flightD, app.dbs.flightly.get(userId+flightD.id));
if (changes.length > 0) {
await app.client.chat.postMessage({
channel: userId,
text: changes.join("\n"),
text: `Flight updates for \`${flightId}\`\n`+changes.join("\n"),
});
}
app.dbs.flightly.set(userId, flightD);
app.dbs.flightly.set(userId+flightD.id, flightD);
await new Promise((r) => setTimeout(r, 1000));
}
await new Promise((r) => setTimeout(r, 250));
}
}
export async function getTextVersionOfData(flightId: string) {