14
SharePoint Timer Jobs SharePoint Training Series

Best Practices for SharePoint Timer Jobs

Embed Size (px)

Citation preview

SharePoint Timer JobsSharePoint Training Series

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

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

Examples of Timer Jobs in SharePoint

• User Profile Sync

• Solution Deployment

• Search Indexing

• Cleaning up old sites

• Etc..

Timer Jobs in SharePoint Farm

• Central Administration -> Monitoring -> Review Job Definitions

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

Architecture of Timer Jobs

• In simplest terms, a Timer Job is a class which implements the Microsoft.SharePoint.Administration.SPJobDefinition class

• Parameters of SPJobDefinitionName 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

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

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

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

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

Demonstration

SharePointTimer Job

SharePointList SharePoint

WebPart

Yahoo!WeatherService

WOEID: "55864247|1105779|

1100661"

Demonstration

• Refer to http://www.screencast.com/t/0on273cM for screencast

• Code sample: https://github.com/shailensukul/SharePoint.Presentations.TimerJob

• Code snippets: http://presentations.sukul.org/presentations/TimerJobs/TimerJobSnippets.zip

Shailen Sukul @shailensukulReadify

[email protected] http://lnkd.in/bmCW-Pkhttp://presentations.sukul.orghttp://shailensukul.com

Thank You!