SharePoint Variations – The complete Guide – Part 4 – Timer Jobs

Timer jobs are a great feature of SharePoint to use when you need to perform background execution at regular or specific times or when you need to execute code on all or selected servers in the farm.

The Variations feature uses specific SharePoint timer jobs to perform tasks such as creating and propagating sites and pages. The Variation Timer jobs are bound to each web application which contain (or contained in the past) a site collection which has the publishing feature enabled.

You can change the Schedule for each job on the Job Definitions page on the Central Administration Web site. The following timer jobs are used to with Variations:

 

The different Variation Timer Jobs

Variations Create Hierarchies Job Definition

This timer job is responsible to create the variation hierarchy of unspawned labels by creating peers in the new label of sites and pages in the source variation label. By default, this timer job runs once a day.

Class: Microsoft.SharePoint.Publishing.Internal.CreateVariationHierarchiesJobDefinition

 

Variations Create Page Job Definition

This timer job creates peer pages on the target variation sites whenever a user explicitly requests the creation of a variant of a page using the UI (Ribbon or Site Manager) – e.g. if the Automatic Creation option has been disabled and a user decides that a page needs to have a page variant in a different label. By default, this timer job runs hourly.

Class: Microsoft.SharePoint.Publishing.Internal.CreateVariationPageJobDefinition

 

Variations Create Site Job Definition

This timer job creates peer sites when the Automatic Creation option has been disabled and a user manually creates a new variation site using Site Manager. By default, this timer job runs every 5 minutes.

Class: Microsoft.SharePoint.Publishing.Internal.CreateVariationSiteJobDefinition

 

Variations Propagate Page Job Definition

Creates and updates peer pages in target variation label after a page in the source variation label has been approved or after the update has been manually requested by a user through the Ribbon. By default, this timer job runs hourly.

Class: Microsoft.SharePoint.Publishing.Internal.PropogateVariationPageJobDefinition

 

Variations Propagate Site Job Definition

Creates peer sites when the Automatic Creation option is enabled. By default, this timer job runs every 5 minutes.

Class: Microsoft.SharePoint.Publishing.Internal.SpawnSitesJobDefinition

 

Communication between worker process and Timer Jobs

Creating variation hierarchies, spawning sites and pages manually or automatically – all these operations are usually triggered from within the worker process. As the worker process account is often not allowed to write into the configuration database where SharePoint timer jobs live, it is not possible to configure the timer jobs directly.

To overcome this limitation, the configuration data for the timer jobs has to be stored within the current content database and the timer job will pick up the data from there.

WSS provides a built in mechanism for this by providing the SPWorkItemJobDefinition class. Timer job definitions derived from this class are able to read configuration data from work items, which are stored in the ScheduledWorkItems table in the content database. The Sharepoint object model allows adding, reading and removing work items to/from this table.

As many different timer jobs can work on the same ScheduledWorkItems table it is necessary to ensure that each ScheduledWorkItems carries a type information (a unique id) to ensure that the timer job picks up the correct work items.

Related to variations this means that each site or page spawn request and each variation hierarchy creation request is represented by a specific work item in the scheduled work item table. When the appropriate timer job runs the next time, it reads all work items related to this timer job from the ScheduledWorkItems table and processes them one by one. After the timer job has completed the processing of a work item, it removes the work item from the ScheduledWorkItems table.

 

Underlying WSS Timer Job framework

SPJobDefinition

All timer job are persistable objects derived from the SPJobDefinition class.

 

SPPausableJobDefinition

In SharePoint 2010, a new abstract class derived from SPJobDefinition has been included, which supports pausing and restart of timer jobs: SPPausableJobDefinition.

This class declares a second Execute method, which allows to hand-in a job state to the timer job. Timer jobs derived from SPPausableJobDefinition can use this job state (SPJobState) to store values when the job is paused, which can be retrieved later when the job is resumed.

 

SPWorkItemJobDefinition

SharePoint 2007 introduced a SPWorkItemJobDefinition Timer job class derived from SPJobDefinition which provided a framework which allowed the implementation of Timer jobs which process a list of work items of a specific type.

With SharePoint 2010, SPWorkItemJobDefinition now also supports the pause and resume functionality and is now derived from SPPausableJobDefinition.

 

For backward compatibility reasons the class still supports Timer job definitions developed without the pausing functionality in mind.

In SharePoint 2010 the actual Timer job derived from SPWorkItemJobDefinition only has to implement two methods: WorkItemType() which returns the unique ID of the work item type that should be processed in the timer job, and ProcessWorkItem() which processes one single work item of the defined type.

The framework provided in the SPWorkItemJobDefinition base class handles the rest of the processing like reading the work items from the database, updating the Timer job progress (visible as progress bar in the central admin), pausing and resume.

 

Variation Timer Jobs Framework

All variation timer jobs implement the SPWorkItemDefinition class. As many variation timer jobs perform very similar operations, an additional intermediate abstract class VariationsSpawnJobDefinitionBase has been implemented which acts as base class to four of the five variation timer jobs:

 

 

Work Item type for Scheduled Variation Work Items

Timer Job

Workitem Type

CreateVariationHierarchiesJobDefinition

E7496BE8-22A8-45BF-843A-D1BD83ACEB25

CreateVariationSiteJobDefinition

943D4A28-4147-4A73-B4D1-4A9162D4ECE2

CreateVariationPageJobDefinition

726ddd8f-0e23-4c35-88b5-4fba39482515

PropogateVariationPageJobDefinition

EA95AB64-3857-4403-96D0-3AEB3DBDB123

SpawnSitesJobDefinition

5A4B0E0E-0579-4a5d-B233-C2932F031912

13 Comments


  1. This complete blog on variation is very nice and explained in a defined way. really helpful…

    Reply

  2. Pingback from Regular TimerJob e Work Item TimerJobs | Rodrigo Romano – Especialista SharePoint

    Reply

  3. Hello stefan,

    Great Article.

    I came across one issue.
    Peer Pages which are propogated to unpublished state, i want that pages to be published automatically.
    Please suggest something how can i achieve this.

    Thanks,

    Reply

  4. Hi Soyeb,

    thats expected as usually someone needs to translate the content before it should go live in the other label.
    If you have a different usage pattern from that you could use custom event receivers which automatically publish the pages.

    Cheers,
    Stefan

    Reply

  5. Hi Stefan,

    If i have to run these 4 timer jobs manually, then in which order they are supposed to run.

    Thanks and Regards

    Reply

  6. Hi Ashish,

    the 4 timerjobs have different purpose. You need to run the one for your specific requirement.

    Cheers,
    Stefan

    Reply

  7. I have 2 page layouts, one for main site and another for translate site.I want to translate site automatically use translate site page layout at the time page created in translate site using variation.

    Reply

  8. Hi Stefan,
    I want to ask if I want to propagate to a specific variation label, I am looking at “EA95AB64-3857-4403-96D0-3AEB3DBDB123” and AddWorkItems. But I am not sure how to configure it properly. Can you recommend or point me to the right direction? Thanks!
    Eugene

    Reply

  9. Hi Sefan,

    I have to face a problem with SharePoint 2013. I have a custom platform from which one SharePoint 2013 is receiving information (pages) via a web service. I have to disable the VariationPageJobDefinition timer job because everytime I’m receiving a change in the main variation is updating everything in the rest of variations. I have a timer job that is undoing what VariationPageJobDefinition timer job does. So till this point everthing looks easy, the thing is that if I dissable this timer job (Microsoft SharePoint’s one) and I’m creating in SharePoint platform a page manually is not going to be propagated because The timer Job is stoped. Anyone can help me with this? How can I face this problem?

    Thank you very much.

    Reply

    1. Hi Paco,
      I’m not sure what your intention is.
      If you have variations then the idea is that content within the variation label is replicated to the other variation labels.
      You can of course configure variations not to create a variation automatically but to do this always manually using the ribbon.
      In case you would like to have automatic propagation of content enabled you should store content which should not be propagated to other labels in sites outside the variation hierarchy.
      Cheers,
      Stefan

      Reply

  10. Hi Stefan,

    I will explain my platform. I have a SharePoint 2013. My main variation is Spanish, and I have another four variations that are Basque, Catalan, Galego and English. When I’m creating a new aspx page in spanish is propagating (creating) the rest of variations. Till here everything is OK. But if I’m updating this spanish aspx page I DON’T want the VariationPageJobDefinition timer job to do anything, I will do what I need by my self with a diferent timer job. How can I do it? How can I face this? I hope to explain my self in a correct way for you to understand me.

    Thank you very much for your help and best regards.

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.