views:

469

answers:

1

Hi

I am trying to create a timer job in WSS 3.0. My timer job would create the object of SPsite then SPWeb and then SPDocumentLibrary (or possibly picture library)using their GUIDs stored in any xml or database.After that it would take the back up of documents in the document library in some third party application and then delete those documents.

So my question is: what should be my SPJobLockType 'None' or 'Job' or 'ContentDatabase' ideally?? Following is my understanding after reading some articles on timer job. Please correct me if I am wrong at any place as I am quite new to SharePoint

  1. If i use 'None', then my job would run on each server in the farm. Do I really need that? because my job is only modifying /deleting documents(I am modifing only content database through my timer job. Please correct me if I am wrong).

  2. If I use lock type 'Job' , then my job would run only on the server on which job creation code is executed.But it can fulfil my requirement(I think so but i am not sure please correct me if am wrong ).

  3. I have gone through this article for ContentDatabase LockType..It says

in short, it’s almost the same as the Job one, meaning that it only runs one server.. BUT.. as Peter find out at Help needed with custom timerjob in SharePoint 2007 , the job runs for each ContentDatabase that the WebApplication is associated with. Another (quite annoying) fact is that it is not that predictable when it will run on the next content database.

Please give your thoughts/Suggestions.

+3  A: 

Anoop,

The "sweep" type of timer job you're describing is a fairly common one, and I've written a number of them myself for different projects. In this type of timer job, you're processing a set of sites, webs, or lists to perform some sort of maintenance. It's typically easiest to process one site/web/list at a time, and the task being performed isn't the type that needs to be performed with maximum speed (that is, something that would require a concurrent/multi-threaded processing model to complete quickly).

In this type of scenario, I've generally built my timer jobs to use an SPJobLockType of "Job." As you noted, this ensures that only one instance of the timer job is running at any given time within the farm. This avoids collisions that would occur if multiple instances ran with an SPJobLockType of "None," and it also avoids the confusing (at least I find it confusing) mechanism of operation that is associated with an SPJobLockType of "ContentDatabase."

Here's a link to the timer job I wrote and posted out on CodePlex. It performs the same type of sweep (at a slightly higher-level) that you were describing: http://blobcachefarmflush.codeplex.com/SourceControl/changeset/view/53851#797787. An instance of the timer job is created in a FeatureReceiver with the following line of code:

BlobCacheFarmFlushTimerJob newJob = new BlobCacheFarmFlushTimerJob(jobName, housingWebApp, null, SPJobLockType.Job);

Based on my understanding of what you've written, I believe an SPJobLockType of "Job" would be appropriate. You want to ensure that only one instance of your job is running at a time (to prevent two or more instances of the same job from trying to process the same SPSite).

I hope that helps!

Sean McDonough