Tuesday, 16 May 2017

Run Sitecore schedule task one time everyday

I want to share with you an experience I had with schedule in which the client requested to run this task at the same time every day, and to make sure we added sending email at the start and the complete of this task, will may had this request before but not sure if you face the issues I had so though to share the issues and solution with you, you can add comments to this post if you had similar issues and or the same issues and how you solve them.




First thing I did is to look for a solution online, you know our sitecore community is becoming bigger and bigger and it has to be someone how came across such a request, I found a couple of good blog posts that you can check through the following links:




After I applied the first solution I still had an issues, following are my issues:
  • The first issue is that the task run for one or two days then stop :) 
  • The second issue is that the task run more than one time during the allowed period set on code :)

See the following code that I used from the first blog post to check if the task is due or not:




After investigation we found the following:

Sitecore instance shutdown in case there are no requests to the site which cause the task to stop running


How we can keep the site a live?

We solved this by creating a windows PowerShell scrip that will keep our sitecore instance a live, following is the script we used, of course we added it to windows Task Scheduler:





So why the task run twice even if we already checking if the last run is not within the due interval,?

The problem was that Sitecore save the Last Run datetime field as any other sitecore datetime field in a UTC format, so you need to convert the Last Run field value to your server time zone before checking if it is due or not.

Following is the code I used to get this time as a server time:



Hope the above will help! :)


1 comment:

MS Azure Training in Hyderabad said...

This information is really awesome thanks for sharing most valuable information.
Sitecore Online Training
Sitecore Training in Hyderabad

Post a Comment