For my upcoming project, one of the requirement was to run a scheduled job every 24 hours. Fair enough I hardly remember how to accomplish this as on my previous projects I was using console application with windows scheduler to do the needful. This time around, I wanted to explore what sitecore offers out of the box for this demands. It was cool, very simple and easy to do so.
Understanding - My first step
I explored couple of blogs to gain understanding on how scheduled tasks and commands work on Sitecore. Please see the references that helped me a lot.
https://sitecorebasics.wordpress.com/2014/08/09/scheduled-task-basics/
https://briancaos.wordpress.com/2011/06/28/run-sitecore-scheduled-task-at-the-same-time-every-day/
https://www.degdigital.com/insights/how-to-create-sitecore-scheduled-task/
For even more deeper understanding and if you have time refer to below as well -
http://www.sitecore.net/Learn/Blogs/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/All-About-Sitecore-Scheduling-Agents-and-Tasks.aspx
Debugging - Crucial One
For triggering the jobs manually, this is for debugging purpose and for us devs with out this, we can not successfully test the code that runs on command trigger. There are multiple options to do this, I found the below module available on market place, it was very easy to install and fairly simple UI to deal with, I tried others, but, I could not make it to work or documentation was missing some steps. I recommend below one -
http://sitecoreblog.blogspot.in/2011/07/new-module-on-trac.html
Note - After you install, many newbies who have not worked on Toolbox might not know where this UI get's installed, it is in "All Programs -> ToolBox -> ScheduledTasksUtil . Click and view all jobs on your instance and trigger any one you wish to debug manually. Cool! Simple! Isn't it.
Actual Bug -
I logged a support ticket for this, I will update this blog post based on sitecore team comments. Though the bug is not huge and has a workaround that we could do for new projects, for teams who might have this issue and if that goes un-recognized could be great deal of problems especially when syncing super important data feed or something.
Here goes the issue -
When I create a scheduled task, there is an option to set the schedule, for example if I need to set a command to run every 24 hours based on documentation by John West, we need to do below as format suggests HH:mm:ss
But, if I have 24 set in the hours, sitecore is reading that as 24 days instead of 24 hours, for any number lesser than 24, it reads correctly as hours.
It does not seem to be an intuitive behavior and looks like a bug while converting hours to days.
On our end, we can proceed by setting this number to less than 24 like 23 as that works fine, but, I wanted to report this regardless as it could be broken on sitecore instances where they had set up a schedule for every 24 hours as this will be running on their end for every 24 days instead of hours.
See some screenshots below.
Example Schedule that has unexpected assignment on schedule -
Loaded up Schedule Object Interval showing 24 days instead of hours.
Work Around (Update from Sitecore team)
It seems this is how .Net above 3.5 deals with it on Time parse. See more details below.
https://connect.microsoft.com/VisualStudio/feedback/details/764618/timespan-parse-24-00-00-returns-24-00-00-00-instead-of-throwing-an-overflowexception
On Sitecore side, the format that has to be used on latest versions of .net frame work would be to use below format for 24 hours.
Example - 20160714|21000714|127|1.00:00:00
Understanding - My first step
I explored couple of blogs to gain understanding on how scheduled tasks and commands work on Sitecore. Please see the references that helped me a lot.
https://sitecorebasics.wordpress.com/2014/08/09/scheduled-task-basics/
https://briancaos.wordpress.com/2011/06/28/run-sitecore-scheduled-task-at-the-same-time-every-day/
https://www.degdigital.com/insights/how-to-create-sitecore-scheduled-task/
For even more deeper understanding and if you have time refer to below as well -
http://www.sitecore.net/Learn/Blogs/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/All-About-Sitecore-Scheduling-Agents-and-Tasks.aspx
Debugging - Crucial One
For triggering the jobs manually, this is for debugging purpose and for us devs with out this, we can not successfully test the code that runs on command trigger. There are multiple options to do this, I found the below module available on market place, it was very easy to install and fairly simple UI to deal with, I tried others, but, I could not make it to work or documentation was missing some steps. I recommend below one -
http://sitecoreblog.blogspot.in/2011/07/new-module-on-trac.html
Note - After you install, many newbies who have not worked on Toolbox might not know where this UI get's installed, it is in "All Programs -> ToolBox -> ScheduledTasksUtil . Click and view all jobs on your instance and trigger any one you wish to debug manually. Cool! Simple! Isn't it.
Actual Bug -
I logged a support ticket for this, I will update this blog post based on sitecore team comments. Though the bug is not huge and has a workaround that we could do for new projects, for teams who might have this issue and if that goes un-recognized could be great deal of problems especially when syncing super important data feed or something.
Here goes the issue -
When I create a scheduled task, there is an option to set the schedule, for example if I need to set a command to run every 24 hours based on documentation by John West, we need to do below as format suggests HH:mm:ss
But, if I have 24 set in the hours, sitecore is reading that as 24 days instead of 24 hours, for any number lesser than 24, it reads correctly as hours.
It does not seem to be an intuitive behavior and looks like a bug while converting hours to days.
On our end, we can proceed by setting this number to less than 24 like 23 as that works fine, but, I wanted to report this regardless as it could be broken on sitecore instances where they had set up a schedule for every 24 hours as this will be running on their end for every 24 days instead of hours.
See some screenshots below.
Example Schedule that has unexpected assignment on schedule -
Loaded up Schedule Object Interval showing 24 days instead of hours.
Work Around (Update from Sitecore team)
It seems this is how .Net above 3.5 deals with it on Time parse. See more details below.
https://connect.microsoft.com/VisualStudio/feedback/details/764618/timespan-parse-24-00-00-returns-24-00-00-00-instead-of-throwing-an-overflowexception
On Sitecore side, the format that has to be used on latest versions of .net frame work would be to use below format for 24 hours.
Example - 20160714|21000714|127|1.00:00:00
Thanks for sharing. Have you seen the Sitecore PowerShell Extensions module on the marketplace? It has a few handy features to help manage the scheduled tasks.
ReplyDelete