-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: automatically retry failed scheduled sends #1660
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release #1660 +/- ##
=============================================
+ Coverage 17.74% 19.57% +1.82%
- Complexity 2316 2389 +73
=============================================
Files 43 45 +2
Lines 8758 9029 +271
=============================================
+ Hits 1554 1767 +213
- Misses 7204 7262 +58 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a newsletter send fails, it'll always send an email to the admin. Given that we're now adding a new retry layer for scheduled newsletters, it's probably best to suppress these emails until the attempts exhaust, otherwise they might get 5 emails regarding the same newsletter. More confusingly, they might get an email when the first attempt fails, only to get resolved by the second attempt.
includes/service-providers/class-newspack-newsletters-service-provider.php
Outdated
Show resolved
Hide resolved
if ( in_array( $new_status, self::$controlled_statuses, true ) && 'future' === $old_status ) { | ||
update_post_meta( $post->ID, 'sending_scheduled', true ); | ||
$result = $this->send_newsletter( $post ); | ||
if ( is_wp_error( $result ) ) { | ||
$prior_attempts = intval( get_post_meta( $post->ID, 'scheduled_send_attempts', true ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not leverage the existing newsletter_send_errors
meta for this? It's persisted and each error entry is already an attempt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f430275 changes the approach to use the newsletter_send_errors
meta.
It might be a good idea to add some exponential backoff. If the first attempt failed because of a server hiccup, it would be fine to try again sooner, like 1 minute, then exponentially try on 2, 4, and 8 minutes. We use something similar for webhooks: |
Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com>
@miguelpeixe thanks for the suggestions!
f430275 should fix this. It was happening because we were deleting the
f430275 also addresses this. If the post has a
bbb656b implements the exponential backoff and also bumps the max retries up to 10, because why not? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! It's working like a charm now. Thank you for the revisions.
Whoops, seems like something is up with the email notification. When sending regularly, the error message includes the link to edit the newsletter. When scheduled, the link is missing: That's because |
@miguelpeixe ad2246c makes the suggested change and seems to work well for me. |
## [3.1.6](v3.1.5...v3.1.6) (2024-09-18) ### Bug Fixes * automatically retry failed scheduled sends ([#1660](#1660)) ([e0cca64](e0cca64))
🎉 This PR is included in version 3.1.6 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [3.2.0-alpha.4](v3.2.0-alpha.3...v3.2.0-alpha.4) (2024-09-20) ### Bug Fixes * a typo that came after a refactor ([#1656](#1656)) ([0ae5b61](0ae5b61)) * automatically retry failed scheduled sends ([#1660](#1660)) ([e0cca64](e0cca64)) * **cc:** urlencode query args before passing to CC API ([#1659](#1659)) ([4f645d2](4f645d2)) * dont send metadata on subscribe ([#1648](#1648)) ([5b4a059](5b4a059)) * handle encoded URLs and block patterns in redirect check ([#1635](#1635)) ([2fa5d16](2fa5d16)) * **mailchimp:** allow contacts to resubscribe after unsubscribing ([#1654](#1654)) ([b76dbc2](b76dbc2)) ### Features * **mailchimp:** parse contact name into merge fields ([#1628](#1628)) ([aeba65a](aeba65a))
🎉 This PR is included in version 3.2.0-alpha.4 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
Implements an auto-retry system for scheduled newsletter sends, and adds logging for scheduled send failures.
#831 fixed handling for failed scheduled sends by resetting the post to
draft
status if a scheduled send failed to happen, but by resetting todraft
status the newsletter must be manually sent or rescheduled. This PR will attempt to automatically retry the send in exponentially increasing intervals up to a maximum of 10 times.How to test the changes in this Pull Request:
return new WP_Error( 'newspack_newsletters_error', 'Temporary error' );
to the first line of theNewspack_Newsletters_Service_Provider::send_newsletter()
method to force a failure upon scheduled send.MAX_SCHEDULED_RETRIES
number down to something like 3 and wait a bit less, then refresh the newsletter in the editor again. Confirm that the post has reverted to "Draft" status with the error message "Failed to send 10 times. Please check the provider connection and try sending again."Other information: