-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Prevent duplication of unsent scheduled reminders #31600
base: master
Are you sure you want to change the base?
Prevent duplication of unsent scheduled reminders #31600
Conversation
…tes' repetition schedule
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
Thanks for this work @webmaster-cses-org-uk - it looks like a very valuable failsafe to have in place. Code change make sense to me, I'm going to have to get creative to test it but will look at it in the coming days. |
@webmaster-cses-org-uk I have been trying to test this just now, and I'm afraid I'm struggling to reproduce the original error. I was attempting to simulate failure of the sending job by commenting out civicrm-core/CRM/Core/BAO/ActionSchedule.php Line 504 in 993588d
action_date_time - but I couldn't replicate the duplicate rows.
The code is very terse... but I thought it might be only when you have a particular configuration of relative dates for the repetition. and UNTIL = 1 hour after Would you be able to share the original config that caused your issue? |
I also noticed a possible issue with the interpretation of 1 minute. It looks to me like
TIMESTAMPDIFF call, which I think would cancel out your correction of parseRepetitionInterval .So I think you might be on the right track, but another step required? |
For the minute thing - I would prefer to remove that option from the config UI (sending emails to a contact every minute is.... not a nice thing to do!) Could you perhaps split out that change for now? And then we can focus on merging the failsafe in this PR? |
(I should say - I haven't confirmed above theory on minute repetition and I could well be reading that SQL wrong. Were you able to get minute-wise reminders actually going out with this change @webmaster-cses-org-uk ? ) |
Overview
This PR provides a fix for the issue identified and discussed in https://lab.civicrm.org/dev/core/-/issues/3824. In the original issue, a server misconfiguration caused the sending of scheduled reminders to fail partway through. This resulted in multiple copies of the same reminder being queued up for sending every time the job ran (even if the reminder was already queued to send), meaning that when the job eventually succeeded, thousands of duplicate reminders were sent to contacts in the database.
Before
When sending a scheduled reminder on a repetition schedule, there is no mechanism to check whether a previous instance of the reminder was already queued to send but never actually got sent. As such, every time the job runs, a new copy of the reminder is queued to send. If and when the emails are actually sent, you get duplicate reminders.
See issue linked above for further details and screenshots etc.
Also, as a side issue, if the repetition schedule is set to 'minutes', this is incorrectly interpreted as 'hours'.
After
When sending a scheduled reminder on a repetition schedule, we now check to make sure that no previous unsent copies exist. If there are, we leave those to be sent but do not queue up a new copy of the reminder to be sent, thus avoiding duplication.
Also, the code to interpret 'minutes' as a schedule interval option is added.
Technical Details
The linked issue includes details of the testing used to simulate the problem and prove that it can be contained by this fix, and to prove that the fix does not interfere with normal sending of reminders.
In addition to this, the proposed fix has been live for > 1 month on a production system running CiviCRM 5.78.3. Reminders have been observed to continue sending as normal.
Comments
This is a robustness improvement to prevent a highly undesirable cascade failure mode (sending many hundreds or thousands of emails to users) in the event of a fault.