Skip to content

Improve handling of SMTP throttling #11187

@davidcornu

Description

@davidcornu

There are cases where we run into Net::SMTPServerBusy because we exceed the rate limit (recent example), and depending on how how the code is written this can result in duplicate emails being sent.

For example, https://github.com/hackclub/hcb/blob/3dbf2fcc7e9318170d20d6c69d420909ed0d4bb3/app/jobs/monthly_donation_summary_job.rb synchronously sends a monthly email for every Event with donations in the last month, and if it runs into Net::SMTPServerBusy Sidekiq ends up retrying the whole thing which causes us to potentially send the same email twice for the records that were processed before the throttle limit was reached.

One option that has been discussed is putting individual email sends on a single queue, which we can then constrain via Sidekiq's capsules (https://github.com/sidekiq/sidekiq/wiki/Advanced-Options#capsules) or a more advanced solution. This would let retries only impact a single email and provide a rudimentary solution to globally throttling outbound email.

Internal discussion: https://hackclub.slack.com/archives/C026RKHLPNJ/p1754018188244529

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions