A Quick-Start Guide to SiteCron’s Scheduled Task Execution
July 17, 2018
Most projects have a requirement to run various tasks (jobs) at a set time. While we have used a variety of approaches to meet this need, SiteCron by Akshay Sura has proven to be the least painful to implement and offers the most reliable execution. The module exists in the Sitecore Marketplace but we’ve found more success by installing it via NuGet.
This post serves as a quick-start guide to SiteCron Scheduled Task Execution, which includes a starter base class. First, I’ll point out some features that may not be obvious when first starting with the module. Then, I’ll cover the steps required to set up a job configured in the database. (Please note: This post DOES NOT cover steps required to set up config-driven jobs, which are also supported by SiteCron.)
- On the primary web project, add the NuGet package SiteCron 3.0.4
- This will add several files to the project
- App_Config\Include\SiteCron\ (SiteCron.config/SiteCronJobs.config)
- SitecorePackage\ (SiteCron FULL Sitecore Package.zip/SiteCron Items Only Sitecore Package.zip)
- These files are not required to be part of the project but are included to facilitate the installation of the Sitecore items required for SiteCron
- This file is not used as part of this example.
- This will add several files to the project
- Install the SitecorePackage\SiteCron Items Only Sitecore Package.zip Sitecore package into your local instance
- There will be no conflicts during installation
- Delete the SitecorePackage folder from the Visual Studio project, it was only included for the module installation
- At this point, SiteCron is fully operational
Start by building a Base Class. This will make logging simpler to execute per job. Note: The jobs should NOT be added to the primary web project. Instead, add them to an accompanying project. You will need to add references to SiteCron.dll and Quartz.dll. Located at:
Next, create your job class.
Configure Job in Sitecore
- After the Sitecore package installation, there will be new items located at: /sitecore/system/Modules/SiteCron
- Right-click the SiteCron item and insert a new Sitecron Folder. This will be the location of all jobs. Organize folders as needed.
- Right-click the new folder and add a new Sitecron Job
- There are two important fields to update:
- This is the fully qualified class and assembly of your job. example: MyProject.MyNamespace.TestJob, MyProject
- Cron Expression
- If you click on the field name, it will bring you to http://www.cronmaker.com/
- This lets you build a cron expression. Note: Server time dictates the time you should use. If the goal is to execute a job at 12:00 am EST, verify the server time is EST, then create the expression:
- Enter the resulting Cron format value, “0 0 0 1/1 * ? *" in the example above, into the Cron Expression field in Sitecore
- Save item
You may also right-click any configured job and select “Execute SiteCron Job Now!” to queue the job to run. It will run a few seconds after requested.
Note: SiteCron provides a few example jobs in the folder /sitecore/system/Modules/Sitecron/OOTB. Feel free to remove these, as they likely won’t be used. Do NOT remove the following items, however:
- /sitecore/system/Modules/Sitecron/OOTB/SiteCron Execution Reports
View Finished Jobs
- The item /sitecore/system/Modules/Sitecron/OOTB/SiteCron Execution Reports is a bucket item installed with SiteCron.
- Select this item and then click the “Search” tab.
- Click the search icon
- This will bring up all previously executed jobs as SiteCron Execution Report items
- Each SiteCron Execution Report item will list
- The time this job ran
- The log written to via the SiteCronBase class
- The unique ID SiteCron uses to identify the job
SiteCron Verified on Sitecore 8 and 9
While it feels satisfying to create something custom, after many custom implementations at GeekHive, we have found great success with SiteCron. We have verified execution on Sitecore 8 and 9. The additional SiteCronBase class makes it very simple to add new jobs as we need them, all with detailed logs of execution.
For a Sitecore developer, SiteCron is a valuable tool to have at your disposal. It avoids reinventing the wheel and lets you focus on your task at hand.
Stay up to date with our email updates!
Like what you've read? There's more where this came from!
Our monthly newsletter features a blog roundup of our top posts so you can stay up to date with industry trends, tutorials, and best practices.