Tuesday 5 February 2013

SharePoint Timer Job demystified

This article talks about some facts about SharePoint Timer Jobs.For those who are not familiar with timer jobs, its a way through which SharePoint related tasks can be scheduled to run in background.


Myth 1: Timer job runs through the Central Administration web application.

Fact: Running your Timer Jobs is completely independent of your Central Administration(CA) web application in the farm. CA is just another web application and it only states Timer job status and its definitions. It is the Windows SharePoint Timer Service(OWSTIMER.EXE) that controls the Timer Job.

Conclusion: So, even if your CA web application goes down(either CA web site or corresponding application pool ), the Timer Job remains unaffected.

Myth 2: Timer Job runs under the security context of Farm Administrator account

Fact: Well, it seems in most of the scenarios that Timer Job runs under the privileges of a Farm Admin account. But the truth is, Timer Job runs the account which is specified as the Log On account for Windows SharePoint Services Timer.

Open Run command  > services.msc  > go to Windows  SharePoint Services Timer > Right Click , select Properties >  Switch to ‘Log On ’ tab.
The account specified in the above figure is responsible to run Timer job. And in most of the production/dev environments the account specified in above figure is also a Farm Admin account, hence we assume that Farm Admin account is responsible to run Timer Job.


Myth 3: RunWithElevatedPriveliges() inside a custom Timer Job executes the block of code under the context of Application pool identity account of targeted web application.

Fact :  The above statement is true when RunWithElevatedPrivileges() is not used inside a Timer Job. When used in a Timer Job it runs under the context of the same account used for running Timer Job i.e. the Windows SharePoint Services Timer account(discussed in Myth 2). The sole intention of using RunWithElevatedPriveleges() is to perform some actions that are otherwise not permitted to. Therefore, in order that our code inside RunWithElevatedPrivileges() block runs successfully , it is necessary that the account under which timer job  runs is also a Site Collection Administrator of targeted web application.
 
Hope this piece of information makes our life easy in SharePoint..;)

No comments:

Post a Comment