A Quick-Start Guide to SiteCron’s Scheduled Task Execution

July 17, 2018

Blog | Development | A Quick-Start Guide to SiteCron’s Scheduled Task Execution
SiteCron Scheduled Task Execution

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.)

SiteCron Installation

  1. 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
      • job_scheduling_data_2_0.xsd
        • This file is not used as part of this example.
  2. Install the SitecorePackage\SiteCron Items Only Sitecore Package.zip Sitecore package into your local instance
    • There will be no conflicts during installation
  3. Delete the SitecorePackage folder from the Visual Studio project, it was only included for the module installation
  4. At this point, SiteCron is fully operational

SiteCron Usage

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:

  • \packages\SiteCron.3.0.4\lib\net452\SiteCron.dll
  • \packages\Quartz.2.5.0\lib\net40-client\Quartz.dll

SiteCronBase.cs

Next, create your job class.

Example Job

Configure Job in Sitecore

  1. After the Sitecore package installation, there will be new items located at: /sitecore/system/Modules/SiteCron
  2. Right-click the SiteCron item and insert a new Sitecron Folder. This will be the location of all jobs. Organize folders as needed.
  3. Right-click the new folder and add a new Sitecron Job
  4. There are two important fields to update:
    1. Type
      • This is the fully qualified class and assembly of your job. example: MyProject.MyNamespace.TestJob, MyProject
    2. 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
  5. 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
  • /sitecore/system/Modules/Sitecron/OOTB/Auto

View Finished Jobs

  1. The item /sitecore/system/Modules/Sitecron/OOTB/SiteCron Execution Reports is a bucket item installed with SiteCron.
  2. Select this item and then click the “Search” tab.
  3. Click the search icon
    • This will bring up all previously executed jobs as SiteCron Execution Report items
  4. Each SiteCron Execution Report item will list
    • LastRunUTC
      • The time this job ran
    • Log
      • The log written to via the SiteCronBase class
    • SitecronJob
      • The unique ID SiteCron uses to identify the job

Execution Report

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.

John Rappel

.NET Practice Lead
Tags
  • Sitecore
  • SiteCron
subscribe to GeekHive's newsletter

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.

Recent Work

Check out what else we've been working on