cambiatus / backend

Cambiatus GraphQL API
GNU Affero General Public License v3.0
20 stars 18 forks source link

Enhancement/add email workers #276

Closed MatheusBuss closed 2 years ago

MatheusBuss commented 2 years ago

What issue does this PR close

Closes #263

Changes Proposed ( a list of new changes introduced by this PR)

Realizar o despacho de emails de claims e transfers através de um sistema de queues e workers

henriquecbuss commented 2 years ago
image

I'm pretty sure it worked 🤣 I got 60+ emails

MatheusBuss commented 2 years ago

I'm pretty sure it worked rofl I got 60+ emails

As funny as this is, it got me thinking. This will probably happen to all users with email enabled as soon as we roll this into prod :upside_down_face:

lucca65 commented 2 years ago

Any way to avoid this @MatheusBuss? Looks a little undesirable 😀

MatheusBuss commented 2 years ago

I'm not entirely sure why it happened in the first place. I don't really know how this was all backlogged. I've received a single outdated email too.

I've been thinking about it and maybe it could have something to do with updating the db_listener?

Other causes could be me messing around with the db itself. I'm not convinced that these emails were sent with oban, since I recall getting oban to work after receiving my email.

Anyway, I'll keep trying to figure it out.

lucca65 commented 2 years ago

at first I thought we would need simply clean oban_jobs table, but it will not work. If you need help let me know we can debug this together

lucca65 commented 2 years ago

bro a place to investigate would be the database triggers. there is a migration that add this. Those triggers are responsible to call this db_listener.ex file

MatheusBuss commented 2 years ago

Just to have it written somewhere. We concluded that the mass email sending happened because the script updated some values on the db. Some of these values were transfers or claims. When these values were updated they triggered the db_listener, which is what we use to know when to send emails. Since there's no distinction between updating or creating values this change told the db_listener to dispatch emails.

MatheusBuss commented 2 years ago

This does not prevent Oban from sending emails yet.

We had discussed making two other issues, one to pause the queue and other to resume it.

We could just implement this one paused to save us one issue though.

lucca65 commented 2 years ago

+1 to merge this one as paused from the get go!

MatheusBuss commented 2 years ago

@lucca65 I've commented the code to put emails on the queue and created #285 to remind us to resume Oban after we roll out this PR.