1

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 PM

04/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 Task

04/27/2018 14:08:11.000 -0400
ManagedPoolThread #2 14:08:11 INFO Starting: Send Weekly Digest Email

04/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 PM

04/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:

enter image description here

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.

  • How long does it take for the task to complete? also how long is your scheduling frequency setting ? <frequency>??:??:??</frequency> – Ahmed Okour Apr 27 '18 at 19:24
  • I included a screenshot that shows the frequency. I have Sitecore Shell Wax installed so it appears as the Date Range, Days, Interval boxes instead of one Frequency field. It's set to run every Friday, every 59:59 minutes. It appears to take about 5 minutes to complete. – Erica Stockwell-Alpert Apr 27 '18 at 19:32
  • It is 2 different job being ran. Based on the INFO log, there are 2 tasks namely: Weekly Digest Email Scheduled Task and Send Weekly Digest Email. From the screenshot you shared it shows there are 2 tasks configured. This is why you have 2 tasks running. 1 is synchronous and the other is asynchronous. Try to remove the synchronous one and see if it fix the issue. – Hishaam Namooya Apr 27 '18 at 20:08
3

Based on the provided log and screenshot, you have 2 different tasks namely

  1. Weekly Digest Scheduled Task

04/27/2018 14:08:11.000 -0400 ManagedPoolThread #8 14:08:11 INFO Starting: Weekly Digest Email Scheduled Task (asynchronously)

  1. Send Weekly Digest Email

04/27/2018 14:08:11.000 -0400 ManagedPoolThread #2 14:08:11 INFO Starting: Send Weekly Digest Email

First one is running asynchronously and the second one is running synchronously.

From the screenshot, you have configured 2 tasks. This is why the emails are sent twice.

Based on those facts, you need to disabled or remove the task that is running synchronously which I think is Weekly Digest Email Manual Task.

| improve this answer | |
  • Are you referring to the Weekly Digest Manual Task and the Weekly Digest Scheduled Task in the content tree? Because the Manual Task is configured to never run, but maybe that's where the problem is? In the interval, I have all of the days unchecked and the interval is set to 00:00:00 – Erica Stockwell-Alpert Apr 30 '18 at 13:44
  • After reviewing Sitecore, I know that the manual task is not causing the issue, because if it was the logs would say "Beginning manual task" (it runs a different command), but based on what you pointed it it seems there must be another task, and the task would be named Send Weekly Digest Email, correct? I'm not sure where that is though, I don't see a task named "Send Weekly Digest Email" anywhere in my content tree. – Erica Stockwell-Alpert Apr 30 '18 at 13:57
  • So, turns out there was another Schedule for this task that a previous developer created that was hidden in the Content tree :) It never even occurred to me to look there, but I searched for that task name and found the culprit. Thanks! – Erica Stockwell-Alpert Apr 30 '18 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.