Timer jobs in SharePoint perform important background processes like user profile synchronization, search indexing, and cleaning up old sites. They run on one or more servers on a scheduled basis independently of users. Examples of timer jobs include user profile synchronization, solution deployment, search indexing, and cleaning up old sites. Timer jobs are implemented as classes that extend the SPJobDefinition class and override the Execute method to contain the job's logic.
2. Shailen is a SharePoint, Office 365 and Azure Consultant.
He has worked for large clients in the US and Australia and is also known as an architect, trainer, and evangelist.
He currently works as a Senior Consultant for Readify.
He is a co-organizer of the SharePoint user group in Melbourne (MPSPUG), Australia and presents to local and
international user groups and at technical conferences, such as SharePoint Saturday.
He is also an MCT and trains on SharePoint/Office365/Azure and runs private and public training classes and
workshops.
Follow him on Twitter at @shailensukul, check out his blog at http://shailensukul.com and presentations at
http://presentations.sukul.org
About Me
3. About Timer Jobs
• What is a timer job?
• Performs much of the backend work to maintain a farm
• Runs on one or more server at a scheduled time
• Runs periodically and independent of users
• Can be load balanced
• What is suitable for?
• Offloading long running processes from web front end server
• Running code under higher privileges
• Is the “hammer” approach
4. Examples of Timer Jobs in SharePoint
• User Profile Sync
• Solution Deployment
• Search Indexing
• Cleaning up old sites
• Etc..
5. Timer Jobs in SharePoint Farm
• Central Administration -> Monitoring -> Review Job Definitions
6. How do Timer Jobs run?
• Windows SharePoint Services Timer Service (SPTimerV4) runs timer jobs
• Service must be enabled and running on each server
• The timer job executes under OWSTIMER.exe in the Services Console Panel
7. Architecture of Timer Jobs
• In simplest terms, a Timer Job is a class which implements the
Microsoft.SharePoint.Administration.SPJobDefinition class
• Parameters of SPJobDefinition
Name Description
Name Name of the job
Service An instance of the SPService class which owns this job
WebApplication Parent SPWebApplication instance
Server An instance of the SPServer class associated with this job
LockType An SPJobLockType value that indicates the circumstances
under which multiple instances of the job can run
simultaneously
8. Architecture of Timer Jobs
• SPJobLockType values
Value Description
None No locks. The timer job runs on every
machine on which the parent service
is provisioned
ContentDatabase Job runs for each content database
associated with the job’s web
application
Job Only one server can run the job at a
time
9. Architecture of Timer Jobs
• Implement the SPJobDefinition class
• Override the Execute method of the
SPJobDefinition class and replace the
code in that method with the code that
your job requires
• The targetInstanceId maps to the GUID
of the current content database while
the timer job is running
10. Developing a Timer Job
• Create the timer job class
• Create the timer job settings class
• Add business logic
• Add a SharePoint feature to install and uninstall
• Provide utility to update timer job settings as part of the
installation
11. Demonstration
• Contoso wants to display weather data in their SharePoint Intranet
site.
• They get their weather data from Yahoo
• The outgoing public connection is not reliable, therefore they
want to cache weather data in SharePoint
• Additional weather locations should be added without any coding
change