Top Banner
SharePoint Timer Jobs SharePoint Training Series
14
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Best Practices for SharePoint Timer Jobs

SharePoint Timer JobsSharePoint Training Series

Page 2: Best Practices for SharePoint Timer Jobs

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

Page 3: Best Practices for SharePoint Timer Jobs

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

Page 4: Best Practices for SharePoint Timer Jobs

Examples of Timer Jobs in SharePoint

• User Profile Sync

• Solution Deployment

• Search Indexing

• Cleaning up old sites

• Etc..

Page 5: Best Practices for SharePoint Timer Jobs

Timer Jobs in SharePoint Farm

• Central Administration -> Monitoring -> Review Job Definitions

Page 6: Best Practices for SharePoint Timer Jobs

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

Page 7: Best Practices for SharePoint Timer Jobs

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

Page 8: Best Practices for SharePoint Timer Jobs

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

Page 9: Best Practices for SharePoint Timer Jobs

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

Page 10: Best Practices for SharePoint Timer Jobs

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

Page 11: Best Practices for SharePoint Timer Jobs

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

Page 12: Best Practices for SharePoint Timer Jobs

Demonstration

SharePointTimer Job

SharePointList SharePoint

WebPart

Yahoo!WeatherService

WOEID: "55864247|1105779|

1100661"

Page 13: Best Practices for SharePoint Timer Jobs

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

Page 14: Best Practices for SharePoint Timer Jobs

Shailen Sukul @shailensukulReadify

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

Thank You!