In this blog post we will be looking into building two SiteCron jobs, one for Smart publish and one for Incremental publish.
- Add a reference to Quartz.dll in your project
- 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); } }
- 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); } }
- Build and deploy to the Sitecore folder
- Login to Sitecore admin and go to /sitecore/system/Modules/Sitecron
- Add a new SiteCron job and name it Scheduled Smart Publish and set the values accordingly (Mon – Fri, run at 6:15AM):
- Add a new SiteCron job and name it Scheduled Incremental Publish and set the values accordingly (Mon – Fri, run at 3:30AM):
- 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.