mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
deliver_scheduled_emails: Use a queue, instead of infinite retries.
`deliver_scheduled_emails` tries to deliver the email synchronously, and if it fails, it retries after 10 seconds. Since it does not track retries, and always tries the earliest-scheduled-but-due message first, the worker will not make forward progress if there is a persistent failure with that message, and will retry indefinitely. This can result in excessive network or email delivery charges from the remote SMTP server. Switch to delivering emails via a new queue worker. The `deliver_scheduled_emails` job now serves only to pull deferred jobs out of the table once they are due, insert them into RabbitMQ, and then delete them. This limits the potential for head-of-queue failures to failures inserting into RabbitMQ, which is more reasonable than failures speaking to a complex external system we do not control. Retries and any connections to the SMTP server are left to the RabbitMQ consumer. We build a new RabbitMQ queue, rather than use the existing `email_senders` queue, because that queue is expected to be reasonably low-latency, for things like missed message notifications. The `send_future_email` codepath which inserts into ScheduledEmails is also (ab)used to digest emails, which are extremely bursty in their frequency -- and a large burst could significantly delay emails behind it in the queue. The new queue is explicitly only for messages which were not initiated by user actions (e.g., invitation reminders, digests, new account follow-ups) which are thus not latency-sensitive. Fixes: #32463.
This commit is contained in:
committed by
Tim Abbott
parent
7fde5fd0a4
commit
c5200e8b05
@@ -14,6 +14,7 @@ from scripts.lib.zulip_tools import atomic_nagios_write, get_config, get_config_
|
||||
|
||||
normal_queues = [
|
||||
"deferred_work",
|
||||
"deferred_email_senders",
|
||||
"digest_emails",
|
||||
"email_mirror",
|
||||
"email_senders",
|
||||
@@ -49,7 +50,7 @@ MAX_SECONDS_TO_CLEAR: defaultdict[str, int] = defaultdict(
|
||||
digest_emails=1200,
|
||||
missedmessage_mobile_notifications=120,
|
||||
embed_links=60,
|
||||
email_senders=240,
|
||||
deferred_email_senders=240,
|
||||
)
|
||||
CRITICAL_SECONDS_TO_CLEAR: defaultdict[str, int] = defaultdict(
|
||||
lambda: 60,
|
||||
@@ -57,7 +58,7 @@ CRITICAL_SECONDS_TO_CLEAR: defaultdict[str, int] = defaultdict(
|
||||
missedmessage_mobile_notifications=180,
|
||||
digest_emails=1800,
|
||||
embed_links=90,
|
||||
email_senders=300,
|
||||
deferred_email_senders=300,
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user