Skip to content

Commit

Permalink
Fix Notification Creation Logic
Browse files Browse the repository at this point in the history
Some siteAlerts were still unprocessed.       This was because these siteAlerts do not have any associated enabled-alertMethod, so they were not considered by the SQL query. To address these unprocessed siteAlerts, I added another SQL to process all remaining unprocessed siteAlerts.
  • Loading branch information
dhakalaashish committed Dec 5, 2023
1 parent f24b3a4 commit 4939404
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/server/src/Services/Notifications/CreateNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ const createNotifications = async () => {
totalSiteAlertProcessed += siteAlertProcessed

if(siteAlertProcessed === 0){
// All notifications have been created, however, there might be some siteAlerts that are still unprocessed
// This is because these siteAlerts do not have any associated enabled-alertMethod, so they were not considered by the SQL above
// To address these unprocessed siteAlerts, update isProcessed for all remaining unprocessed siteAlerts to true
const updateSiteAlertIsProcessedToTrue = Prisma.sql`
UPDATE "SiteAlert" SET "isProcessed" = true WHERE "isProcessed" = false AND "deletedAt" IS NULL`;
await prisma.$executeRaw(updateSiteAlertIsProcessedToTrue)
// Exit the while loop
moreAlertsToProcess = false; // No more alerts to process, exit the loop
}else {
await new Promise(resolve => setTimeout(resolve, 200)); // Delay of 1/5 second
Expand Down

0 comments on commit 4939404

Please sign in to comment.