I have a scheduled task for sending out weekly emails to users who have subscribed. I have my task created in Sitecore and set to run on Fridays, at a minimum interval of 00:59:59; in the code, it checks if the current time is between 2-3PM and if so, continues to complete the task. Therefore the emails should only send once on Friday between 2 and 3 PM, but instead they are sending twice within one minute.
Another issue I had is that even though my Sitecore task was configured to run every 59 minutes, it instead was originally sending emails every ten minutes. I fixed this with a code change that updates the "Last Run" field on my email settings item, and does not send emails if "Last Run" is the current day. This stopped the emails from going out every 10 minutes, but I still get the double.
From looking at my logs, this is what I see:
04/27/2018 14:08:11.000 -0400
ManagedPoolThread #8 14:08:11 INFO Starting: Weekly Digest Email Scheduled Task (asynchronously)04/27/2018 14:08:11.000 -0400
ManagedPoolThread #13 14:08:11 INFO Weekly Digest Task last ran at 4/20/2018 2:02:04 PM04/27/2018 14:08:11.000 -0400
ManagedPoolThread #13 14:08:11 INFO Running scheduled task!04/27/2018 14:08:11.000 -0400
ManagedPoolThread #8 14:08:11 INFO Ended: Weekly Digest Email Scheduled Task04/27/2018 14:08:11.000 -0400
ManagedPoolThread #2 14:08:11 INFO Starting: Send Weekly Digest Email04/27/2018 14:08:11.000 -0400
ManagedPoolThread #2 14:08:11 INFO Weekly Digest Task last ran at 4/20/2018 2:02:04 PM04/27/2018 14:08:11.000 -0400
ManagedPoolThread #2 14:08:11 INFO Running scheduled task!
So it appears that the task is triggering twice in the same second. When it checks "Last Run" the second time, the field has not been updated yet, so it still appears that it last ran a week ago and not the same day. I checked the "Last Run" field after the emails sent today, and it says it last ran at 4/27/2018 2:02:08 PM
This is how my task is configured in Sitecore:
Would unchecking Async fix it? I'm hesitant that making it not asynchronous will slow down the site when the task is running. It is also difficult to test since the task only runs once a week and any time it runs it is sending emails to real users, so I can't just run it a ton of times to test it.