SiteCron Sitecore module for your everyday scheduling needs

SiteCron is a scheduling module based on Quartz.NET Job Scheduler. SiteCron can be used to create simple or complex schedules to execute jobs. This functionality is implemented using Quartz’s CronTrigger.

“Quartz.NET is a pure .NET library written in C# and is a port of very popular open source Java job scheduling framework, Quartz.”

Cron has been around for a long time and is known for its powerful scheduling capabilities. CronTrigger in Quartz is based on the scheduling capabilities of cron and uses “cron expressions” to execute the jobs. Cron expressions specify the condition to fire the job such as execute this job at 8AM each day.

The current implementation of SiteCron only uses CronTrigger functionality of Quartz, which is more useful than the SimpleTrigger. It lets you have a job-firing schedule that recurs based on calendar type scenarios rather than on the exactly specified intervals of SimpleTrigger. The interval based jobs can be run using Sitecore agents.

CronTrigger lets you fire jobs based on schedules such as:

  • Fire job every friday at 9PM
  • Fire job every day at 8AM from monday to thursday
  • Fire job every 3 minutes from 2PM to 4PM
  • Fire job at 3 pm on monday and wednesday

Module installation is simple using the package installation in the Sitecore admin. Once the module is installed it gets initialized via the Initialize pipeline.

    
    
      
        
      
    

Each time a job is saved or deleted, SiteCron reloads all schedules for consistency. There are OnSaved and OnDeleted events implemented to take care of this.

    
    
      
        
      
      
        
      
    

The implementation of the CronTrigger is done using the code below:

    IJobDetail jobDetail = JobBuilder.Create(jobType).Build();

    ITrigger trigger = TriggerBuilder.Create()
        .WithIdentity(i.Name)
        .WithCronSchedule(i[cronExpressionField])
        .ForJob(jobDetail)
        .Build();
    scheduler.ScheduleJob(jobDetail, trigger);

Here is an example of the IJob implementation:

using Quartz;
using Sitecore.Diagnostics;

namespace Sitecron.Samples
{
    public class SampleLogJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Log.Info("Sample Log Job - Add Log Entry.", this);
        }
    }
}

The module has a check for Publishing.PublishingInstance setting, this is mainly used when Scalability settings are enabled. If you are in a multi-server environment, we want the scheduler to trigger only on the primary designated server. This setting will ensure that the check to validate the current instance to the publishing instance is verified.

Here are the steps to implement a job for SiteCron:

  1. Add a reference to Quartz.dll in your project
  2. Implement a new class which implements Quartz.IJob
  3. Build and deploy to the Sitecore folder
  4. Login to Sitecore admin and go to /sitecore/system/Modules/Sitecron
  5. Add a new SiteCron job
  6. Set the Type to Class Namespace, Assembly
  7. Set the Cron Expression for the schedule and save

I plan on using this for Scheduled site publishes at specific times during the day to avoid peak traffic.

For more information on CronTriggers please visit the following urls:
http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/crontriggers.html

For help with Cron Expressions you can use http://www.cronmaker.com/

Expressions
0 15 10 * * ? Fire at 10:15am every day
0 15 20 * * ? * Fire at 10:15pm (20:15) every day
0 15 10 * * ? 2015 Fire at 10:15am every day during the year 2015
0 15 10 ? * MON-FRI Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday
0 15 10 15 * ? Fire at 10:15am on the 15th day of every month
0 15 10 L * ? Fire at 10:15am on the last day of every month
0 0 12 1/5 * ? Fire at 12pm (noon) every 5 days every month, starting on the first day of the month.

It’s alive!! SiteCron published on the Sitecore marketplace! https://marketplace.sitecore.net/Modules/S/Sitecron.aspx?sc_lang=en

If you have any questions or comments, please be sure to reach out.

6 thoughts on “SiteCron Sitecore module for your everyday scheduling needs”

  1. Installed Sitecron 1.1.6, everything appears to be in place, though does not appear to trigger. Have used code examples and it does not launch into. This is currently in our development environment.

    Is there a service that this creates that I can check for to be sure it is running?

    I ran so it would trigger every minute while attached via Visual Studio and would not break into code.

    ideas?

  2. The only thing I can think of is the destination job. Can you send me a screenshot or the content of your job please?

  3. Hello Akshay,

    Thanks for this article.

    I implemented this package and the code. But the logs shows some issues with Common.Logging version.
    It says “Could not load file or assembly ‘Common.Logging, Version=3.0.0.0’ ” Although installed the Quartz from Nuget Console which added Common.Logging assemblies with version 3.3.1. But unable to figure out why it needs 3.0.0.0. Any inputs will be much appreciated.

  4. Common.Logging is a dependency on Quartz.NET. Not sure if you have any assembly binding in your web.config, I would check there.

  5. We seem to have issues when this is setup with multiple servers. Is there known issues when configured this way?

Leave a Reply

Your email address will not be published. Required fields are marked *