Wednesday, June 10, 2009

Create SharePoint Job Timer Definitions

So I realized recently that one of my MOSS applications did not have all of the timer jobs defined for it that it should have. You know, you go to Central Admin -> Operations -> Job Timer Definitions and they just aren't all there. Which ones should be there by default? Here's a good list. Just how do you go about getting some of those jobs in there? There's a bunch of tricks and supported approaches.

The publishing tasks (Scheduled Approval, Scheduled Page Review, etc.) can be created in one shot by creating a new web site collection using the publishing portal template under the existing application and deleting it. The timer definitions stay, the services start running and everyone is happy. Yaaaay!

Some of the definitions will be created if you set the appropriate properties using stsadm.
E.g., stsadm -o setproperty -pn job-immediate-alerts -pv "Every 5 minutes between 0 and 59" -url http://your-site.com
Once again the timer job shows up and most of the time your alerts start flowing. Hooray for our side!

But there are a bunch of definitions that there don't appear to be tools to create on their own. Sure you can back up the database, blow away the application, create a new application with the correct template and same name, restore the database, and fix the issues (there's always some). I didn't want to go through all that, though I'm not sure that what I figured out was less work. What I ended up doing was to write some crafty SQL. Well, maybe it was just plain old mundane and obvious SQL, but that's what I did. All the answers lie in the Objects table in your config database.

First find the id of your web application. This is going to be the parent id of the timer record you will insert. The following SQL worked pretty well for me.

SELECT * FROM Objects WHERE Properties LIKE '%SPWebApplication%'

Next, query the table and look for existing definitions of the jobs you are missing. If you don't already have an application that contains them, you can create one. The Name column of the records contains the stsadm property for each timer job. Here's a list of a few. And here's some SQL to help you out.

SELECT * FROM Objects WHERE o.Name LIKE 'job-%'

Find a record for the job you are interested in. You will need two pieces of information: the ClassId and the Properties contents. The classId tells the system which timer job to create and the Properties contain the frequency of the timer job and a couple of other easy to change settings.

Last, run a simple insert statement like the following...
INSERT Objects(Id, ClassId, ParentId, Name, Status, Properties)
VALUES (NEWID(), '[JobClassId]', '[ParentApplicationId]', '[JobPropertyName]', 0,'[PropertyContents]')

A quick refresh of the Timer Job Definitions page will show the new job ready to run. You may need to restart the Windows SharePoint Services Timer service before the new jobs are picked up though. Also, the Timer Job Status list will not show the new jobs until after the first time they are run. Be patient for those weekly tasks.

Again with the disclaimer: I saw in some posts that Microsoft doesn't take to kindly to messing around with the SharePoint databases. If you want continued support, tweak at your own risk. This should really only be used as a last resort in any case as there are usually other options. I just happened across someone asking this question and decided to figure out how to do it.


No comments:

Post a Comment