Conversation
The "Send emails" task runs every minute and gave each e-mail three tries with no pause between them, so an SMTP outage of about three minutes abandoned every queued e-mail, order confirmations included, until someone requeued them by hand. A failed try now sets DontSendBeforeDateUtc to 1, 5, 15, 30, 60 and then 120 minutes ahead, and an e-mail gets seven tries, which covers almost four hours of outage. The field and its filter already exist, so no migration is needed. A run stopped mid-send still does not count as a try.
The pauses between tries of a failed e-mail move to the new "QueuedEmail" section (RetryDelayMinutes), so an installation can cover a longer or a shorter SMTP outage without a code change. The try limit still follows from the list: one try more than there are pauses. A missing or empty list keeps the default of 1, 5, 15, 30, 60 and 120 minutes. A negative try count no longer indexes the list, which would have thrown from the catch block and stopped the run for every e-mail after it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type: bugfix
Issue
The "Send emails" task runs every minute, takes up to 500 queued e-mails and gives each one three tries (
maxTries = 3) with no pause between them. A fast-failing SMTP outage of about three minutes (refused connection, DNS failure, provider maintenance) used up every try, and the e-mails were abandoned: order confirmations, password recovery links, everything. Recovery was manual (Admin → Queued emails → Requeue, one by one).Solution
A failed try now postpones the next one through the existing
QueuedEmail.DontSendBeforeDateUtc, whichSearchEmails(loadOnlyItemsToBeSent: true)already honours. The pauses come from a new appsettings section, in all four hosts:0retries on the next run.QueuedEmailConfigis bound like the other config sections (StartupBase) and injected into the task, the same wayAuditLogRetentionScheduleTaskgetsAuditConfig. The property has no initializer on purpose: the configuration binder would otherwise mix the defaults with the configured values.DontSendBeforeDateUtcas it was. The last failed try does not set it, because no try is left. A negative try count (from a direct database edit) is counted without a pause instead of throwing and stopping the run.Out of scope: telling transient SMTP errors apart from permanent ones. A permanently failing e-mail now uses up its tries over about four hours instead of 3 minutes.
Breaking changes
None. The Admin queued e-mail list defaults to "max sent tries 10", so e-mails abandoned after 7 tries still show in the list.
Testing
dotnet test src/Tests/Grand.Modules.Tests --filter QueuedMessagesSendScheduleTaskTests. They check:localhoston port1.Sent tries1 and "Don't send before" about 1 minute ahead. The run after that shows 2 tries and about 5 minutes ahead.QueuedEmail:RetryDelayMinutesto[ 2 ], restart, and check that a new failing e-mail waits 2 minutes and is abandoned after its second try.