api icon indicating copy to clipboard operation
api copied to clipboard

Send email notifications for campaign milestones ONLY once

Open slavcho opened this issue 2 years ago • 1 comments

Which area(s) of Podkrepi.bg are affected? (leave empty if unsure)

No response

Describe the Bug

Currently if too many donations come very fast, due to the lack of safe synchronization, we will send multiple email notifications. We rely on the database to check if such a notification was already sent.

We don't have that many donations at the moment, but still. This can become potentially a problem in the light of the automated b2b donations. There we can expect that many small donations will arrive very often.

My best guess here is that we need to use the PostgreSQL transactions for that. And raise an event only if it was the current donation that moved the needle above the threshold.

To Reproduce

I assume we can reproduce this even with a unit test.

Expected Behavior

Should send only 1 notification when the raised amount goes above the thresholds (of 50%, 90%, or 100%)

Which browser are you using? (if relevant)

No response

slavcho avatar Aug 17 '23 10:08 slavcho

FYI it looks like NestJS has integrated a message queue that helps for jobs in a multi-node environment: https://docs.nestjs.com/techniques/queues it has some capabilities of running a duplicated job only once as per this guide: https://docs.bullmq.io/guide/jobs/repeatable

igoychev avatar Aug 28 '23 09:08 igoychev