This commit is contained in:
Kfir Dayan 2023-08-06 10:48:24 +03:00
parent 3aeb79f054
commit 1f59ccfb2c

View file

@ -17,30 +17,39 @@ class App {
async startCronJob() { async startCronJob() {
console.log("START CRON JOB"); console.log("START CRON JOB");
const newGamesAdded = [];
await this.googleCalendar.init(); await this.googleCalendar.init();
// Schedule the job to run daily at a specific time (e.g., 1:00 AM) // Schedule the job to run daily at a specific time (e.g., 1:00 AM)
try { try {
const games = await app.gameSource.getGamesFromHaifa(); const games = await app.gameSource.getGamesFromHaifa();
for (const game of games) { for (const game of games) {
const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent( const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(
game.start.dateTime, game.start.dateTime,
game.end.dateTime, game.end.dateTime,
game.summary game.summary
); );
if (!isDuplicateEvent) { if (!isDuplicateEvent) {
console.log("Event does not exist"); newGamesAdded.push(game);
await this.googleCalendar.updateNewEvent([game]); console.log("Event does not exist");
} else { await this.googleCalendar.updateNewEvent([game]);
console.log("Event already exists"); } else {
} console.log("Event already exists");
console.log("Event:");
console.log("Happening at:");
} }
} catch (error) {
console.error("Error in cron job:", error.message);
} }
if(newGamesAdded.length > 0) {
console.log("New games added:", newGamesAdded);
} else {
console.log("No new games added");
}
} catch (error) {
console.error("Error in cron job:", error.message);
}
} }
} }