SharePoint 2016: How to Create and Run a Time Job in a Farm that Doesn't Have a Server Application Role Type

  • In this article, I'll show you how to create and run a time job in a farm server Application role type in SharePoint 2016.
A.   The Server Farm SharePoint 2016 includes:
-          Server Architecture:
Server Name
Description
1.    SQLDBSQL Server
2.    SharePoint ServerSharePoint Web Front End 1
3.    WFE1SharePoint Web Front End 2
4.    WFE2Application Search Server
B.    SPJobLockType on multi-WFE farms - SharePoint 2016.
-       When you create a custom timer job, you inherit from SPJobDefinition. A couple of the constructors for the job allows you to specify a value for the lock type used by the job. This value is set as an enum of type SPJobLockType.

-       The MSDN documentation details the available values for the SPJobLockType enumeration as follows:
Member nameDescription
NoneProvides no locks. The timer job runs on every machine in the farm on which the parent service is provisioned, unless the job I associated with a specified server in which case it runs on only that server (and only if the parent service is provisioned on the server).
Content DatabaseLocks the content database. A timer job runs one time for each content database associated with the Web application.
JobLocks the timer job so that it runs only on one machine in the farm.

C.   Create Timer Job step-by-step
1.    Open the Visual Studio 2015
2.    Click New Project.
3.    Select the Empty SharePoint Solution Template.

4.    Select Deploy as a farm solution.

5.    Add a new class to the project and provide the name (BambooTimerJobFarmDemo.cs)
6.    Derive this  BambooTimerJobFarmDemo.cs from the SPJobDefinition class.
7.    You need to add the following statements to do this.
8.    Add the following three constructors to your class. (For Multi-Server SharePoint Farm have installed the Application Search Server).

9.    Add the following three constructors to your class. (For The Server SharePoint doesn't have install the Application Search Server).

10.    Override the Execute() method to do your stuff. Whenever the timer job executes, it will run the code written inside the Execute() method.

D.   Register the Timer Job Definition
-       Use the following the procedure to register the Timer Job Definition:
1.  Add a new feature to register our custom timer job.
2.  Right-click on Features inside the project in the Solution Explorer and click "Add Feature".
3.  Rename this feature to BambooTimerJobFarm2016 Feature
4.  Select the scope of the Timer job as "WebApplication".

5.    Right-click on the "BambooTimerJobFarm2016Feature" and select "Add Event Receiver".
6.    Uncomment the FeatureActivated and FeatureDeactivating methods and write the code as in the following.
7.    Right-click on the project name in your Solution Explorer and select Deploy.
8.    After successfully deploying it, activate the feature
9.    Open Central Administration and select Manage Web Application.
10.    Select your web application.
11.    Select the "Manage Feature" tab on the ribbon control.
12.    Select the web application and find the job.

E.   Timer job run lists 

Comments