Skip to content

Commit

Permalink
change region
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sidhdhi-p committed Sep 23, 2024
1 parent 40e58b3 commit 2f880f1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion khelo/functions/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
9 changes: 6 additions & 3 deletions khelo/functions/src/match/match_repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions khelo/functions/src/match/match_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion khelo/functions/src/notification/notification_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions khelo/functions/src/team/team_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 2f880f1

Please sign in to comment.