← All posts

Sitecore

Smart and Incremental publish using SiteCron for Sitecore

Akshay SuraLeave a comment

In this blog post we will be looking into building two SiteCron jobs, one for Smart publish and one for Incremental publish.

  1. Add a reference to Quartz.dll in your project
  2. Implement a new class called SmartSitePublishJob which implements Quartz.IJob, sample code is shown below:
        public class SmartSitePublishJob : IJob
        {
            public void Execute(IJobExecutionContext context)
            {
                Log.Info("SmartSitePublishJob Execute - Start", this);
    
                Database master = Sitecore.Configuration.Factory.GetDatabase("master");
    
                Database[] targetDBs = new Database[] { Sitecore.Configuration.Factory.GetDatabase("web") }; //you can get this via config if you need customize targets
                Language[] languages = languages = LanguageManager.GetLanguages(master).ToArray();
    
                Sitecore.Publishing.PublishManager.PublishSmart(master, targetDBs, languages);
    
                Log.Info("SmartSitePublishJob Execute - End", this);
            }
        }
    
  3. Implement a new class called IncrementalSitePublishJob which implements Quartz.IJob, sample code is shown below:
        public class IncrementalSitePublishJob : IJob
        {
            public void Execute(IJobExecutionContext context)
            {
                Log.Info("IncrementalSitePublishJob Execute - Start", this);
    
                Database master = Sitecore.Configuration.Factory.GetDatabase("master");
    
                Database[] targetDBs = new Database[] { Sitecore.Configuration.Factory.GetDatabase("web") }; //you can get this via config if you need customize targets
                Language[] languages = languages = LanguageManager.GetLanguages(master).ToArray();
    
                Sitecore.Publishing.PublishManager.PublishIncremental(master, targetDBs, languages);
    
                Log.Info("IncrementalSitePublishJob Execute - End", this);
            }
        }
    
  4. Build and deploy to the Sitecore folder
  5. Login to Sitecore admin and go to /sitecore/system/Modules/Sitecron
  6. Add a new SiteCron job and name it Scheduled Smart Publish and set the values accordingly (Mon – Fri, run at 6:15AM):
    SiteCron_Smart_Publish
  7. Add a new SiteCron job and name it Scheduled Incremental Publish and set the values accordingly (Mon – Fri, run at 3:30AM):
    SiteCron_Incremental_Publish
  8. Once saved the jobs are added to the scheduler and triggered accordingly.

Here are some useful links:

Video: SiteCron Demo
GitHub: https://github.com/akshaysura/Sitecron
Market Place: https://marketplace.sitecore.net/Modules/S/Sitecron
For help with Cron Expressions you can use http://www.cronmaker.com/
You can get more information about the Cron triggers and examples from Quartz.NET Scheduler website at: http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/crontriggers.html

If you have any questions or comments, please get in touch with me.