From 2f880f114fc450070d4cb07603d0c87902aaf9b6 Mon Sep 17 00:00:00 2001 From: sidhdhi canopas Date: Mon, 23 Sep 2024 12:15:14 +0530 Subject: [PATCH] change region --- khelo/functions/src/index.js | 2 +- khelo/functions/src/match/match_repository.js | 9 ++++++--- khelo/functions/src/match/match_service.js | 4 ++-- khelo/functions/src/notification/notification_service.js | 2 +- khelo/functions/src/team/team_service.js | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/khelo/functions/src/index.js b/khelo/functions/src/index.js index b4b9a3bf..dc5570fa 100644 --- a/khelo/functions/src/index.js +++ b/khelo/functions/src/index.js @@ -66,7 +66,7 @@ exports.teamPlayerChangeObserver = (0, firestore_2.onDocumentUpdated)({region: R await teamService.notifyOnAddedToTeam(oldTeam, newTeam); }); -exports.fiveMinuteCron = (0, scheduler.onSchedule)({timeZone: exports.TIMEZONE, schedule: "*/5 * * * *"}, async () => { +exports.fiveMinuteCron = (0, scheduler.onSchedule)({timeZone: exports.TIMEZONE, schedule: "*/5 * * * *", region: REGION}, async () => { await matchRepository.processUpcomingMatches(); }); diff --git a/khelo/functions/src/match/match_repository.js b/khelo/functions/src/match/match_repository.js index ac86d2bb..9dceb388 100644 --- a/khelo/functions/src/match/match_repository.js +++ b/khelo/functions/src/match/match_repository.js @@ -16,8 +16,11 @@ class MatchRepository { const NOTIFICATION_WINDOW = 5 * 60 * 1000; // 5 minutes in milliseconds const currentTimestamp = admin.firestore.Timestamp.now(); - const startThreshold = new admin.firestore.Timestamp(currentTimestamp.seconds + NOTIFICATION_THRESHOLD / 1000, 0); - const endThreshold = new admin.firestore.Timestamp(currentTimestamp.seconds + (NOTIFICATION_THRESHOLD + NOTIFICATION_WINDOW) / 1000, 0); + const startThresholdInSeconds = currentTimestamp.seconds + NOTIFICATION_THRESHOLD / 1000; + const endThresholdInSeconds = currentTimestamp.seconds + (NOTIFICATION_THRESHOLD + NOTIFICATION_WINDOW) / 1000; + + const startThreshold = new admin.firestore.Timestamp(startThresholdInSeconds, 0); + const endThreshold = new admin.firestore.Timestamp(endThresholdInSeconds, 0); const upcomingMatchesQuery = this.matchRef() .where("start_at", ">=", startThreshold) @@ -31,7 +34,7 @@ class MatchRepository { }); await Promise.all(promises); } else { - console.log("No upcoming matches found within the notification threshold."); + console.log(`MatchRepository: No upcoming matches found within threshold.from ${startThreshold.toDate().toLocaleString()} to ${endThreshold.toDate().toLocaleString()}`); } } catch (e) { console.error("MatchRepository: Error getting upcoming matches:", e); diff --git a/khelo/functions/src/match/match_service.js b/khelo/functions/src/match/match_service.js index dd617b1a..9f5918aa 100644 --- a/khelo/functions/src/match/match_service.js +++ b/khelo/functions/src/match/match_service.js @@ -18,14 +18,14 @@ class MatchService { ...match.umpire_ids.filter((e) => e !== null), ...match.commentator_ids.filter((e) => e !== null), ]); - console.log("Contributors in match:", matchContributorIds); + console.log("MatchService: Contributors in match:", matchContributorIds); if (matchContributorIds.length === 0) { return; } const matchContributors = await this.userRepository.getUsers([...matchContributorIds]); const usersToNotify = matchContributors.filter((m) => user_models.userNotificationEnabled(m)).map((m)=> m.id); - console.log("Users to notify:", usersToNotify); + console.log("MatchService: Users to notify:", usersToNotify); const teamAName = teamA.name; const teamBName = teamB.name; diff --git a/khelo/functions/src/notification/notification_service.js b/khelo/functions/src/notification/notification_service.js index 3ac38434..c4a64aad 100644 --- a/khelo/functions/src/notification/notification_service.js +++ b/khelo/functions/src/notification/notification_service.js @@ -19,7 +19,7 @@ class NotificationService { } } if (tokens.size == 0) { - console.debug("No tokens found for user"); + console.debug("NotificationService: No tokens found for user"); return; } const payload = { diff --git a/khelo/functions/src/team/team_service.js b/khelo/functions/src/team/team_service.js index 28f84856..01c0553c 100644 --- a/khelo/functions/src/team/team_service.js +++ b/khelo/functions/src/team/team_service.js @@ -12,14 +12,14 @@ class TeamService { const oldPlayers = oldTeam.team_players || []; const newPlayers = newTeam.team_players || []; const addedPlayerIds = newPlayers.filter((player) => !oldPlayers.some((oldPlayer) => oldPlayer.id === player.id)).map((m) => m.id); - console.log("Newly added players:", addedPlayerIds); + console.log("TeamService: Newly added players:", addedPlayerIds); if (addedPlayerIds.length === 0) { return; } const addedPlayers = await this.userRepository.getUsers(addedPlayerIds); const playersToNotify = addedPlayers.filter((m) => user_models.userNotificationEnabled(m)).map((m)=> m.id); - console.log("Players to notify:", playersToNotify); + console.log("TeamService: Players to notify:", playersToNotify); const teamName=newTeam.name; const teamId= newTeam.id; if (playersToNotify.length > 0 && typeof teamId === "string" && typeof teamName === "string") {