feat: add configurable async email delivery for workshop invitations#2592
feat: add configurable async email delivery for workshop invitations#2592mroderick merged 4 commits intocodebar:masterfrom
Conversation
9ef1965 to
1e557b8
Compare
b8708c9 to
1569e2d
Compare
1569e2d to
6285351
Compare
|
I am considering a way to use SendGrid's API to send email in batches of up to 1k each, but that's a bigger undertaking. This PR fixes the immediate problem today, and I can carefully design the other solution without rushing or jeopardising the workshop invitations functionality. |
|
Once this is merged, I'll speak to some chapter organisers from the larger chapters to get them to help test drive this. The last thing we need is for all chapter organisers to be disrupted at the same time. |
till
left a comment
There was a problem hiding this comment.
I am not overly familiar with all the Rubyism, but is codebar already using delay jobs? It seems so as there is not additional setup in this PR. Otherwise, LGTM.
Then my only question is: do we have enough database storage for all these new rows?
I think we'll be ok for a while. We could add a job that cleans out old (1-2y+) rows. |
Summary
ApplicationJobwith global error handling for failed jobsAsyncEmailConcernfor chapter-based async email feature flagWorkshopInvitationManagerto send emails asynchronously for chapters inASYNC_EMAIL_CHAPTER_IDSHypothesis
DelayedJob jobs timeout after 540s on Heroku when processing bulk workshop invitations. This happens because emails are sent synchronously (
deliver_now) inside loops, blocking on SMTP I/O for each email.At scale:
How the Fix Works
ASYNC_EMAIL_CHAPTER_IDS, emails are enqueued with.deliver_laterinstead of blocking with.deliver_nowWhat happens with Heroku Scheduler running every 10 minutes:
jobs:workoffruns, picks up first batch of email jobsjobs:workoff, picks up moreExpected behavior:
Trade-off: Emails are sent over ~10-20 minutes instead of ~13 minutes synchronously. This is preferable to timed-out failures.
Feature Flag
ASYNC_EMAIL_CHAPTER_IDSenv var:Recommended rollout:
ASYNC_EMAIL_CHAPTER_IDS(safe - no behavior change)ASYNC_EMAIL_CHAPTER_IDS=1to enable async for London onlyChanges
config.active_job.queue_adapter = :delayed_joband add feature flag configasync_email_for_chapter?helper