Andrew Connell [MVP SharePoint]
1741 Posts |  46 Articles |  5310 Comments
.NET  |  MCMS  |  SharePoint  |  Office System
Andrew Connell's RSS Feed    
AC's Blog Quick Links
SharePoint Quick Links
Article Categories
Archives
May, 2012 (3)
April, 2012 (4)
March, 2012 (4)
February, 2012 (4)
January, 2012 (12)
December, 2011 (6)
November, 2011 (3)
October, 2011 (17)
September, 2011 (8)
August, 2011 (6)
July, 2011 (7)
June, 2011 (13)
May, 2011 (9)
April, 2011 (15)
March, 2011 (1)
February, 2011 (6)
January, 2011 (5)
December, 2010 (11)
November, 2010 (6)
October, 2010 (12)
September, 2010 (5)
August, 2010 (4)
July, 2010 (5)
June, 2010 (6)
May, 2010 (11)
April, 2010 (11)
March, 2010 (9)
February, 2010 (9)
January, 2010 (3)
December, 2009 (10)
November, 2009 (15)
October, 2009 (15)
September, 2009 (7)
August, 2009 (4)
July, 2009 (10)
June, 2009 (8)
May, 2009 (2)
April, 2009 (9)
March, 2009 (6)
February, 2009 (16)
January, 2009 (6)
December, 2008 (12)
November, 2008 (12)
October, 2008 (27)
September, 2008 (13)
August, 2008 (14)
July, 2008 (14)
June, 2008 (12)
May, 2008 (23)
April, 2008 (12)
March, 2008 (15)
February, 2008 (13)
January, 2008 (12)
December, 2007 (10)
November, 2007 (8)
October, 2007 (15)
September, 2007 (20)
August, 2007 (21)
July, 2007 (16)
June, 2007 (8)
May, 2007 (25)
April, 2007 (16)
March, 2007 (18)
February, 2007 (18)
January, 2007 (12)
December, 2006 (16)
November, 2006 (13)
October, 2006 (18)
September, 2006 (22)
August, 2006 (27)
July, 2006 (23)
June, 2006 (23)
May, 2006 (23)
April, 2006 (9)
March, 2006 (17)
February, 2006 (15)
January, 2006 (23)
December, 2005 (31)
November, 2005 (32)
October, 2005 (38)
September, 2005 (53)
August, 2005 (30)
July, 2005 (63)
June, 2005 (30)
May, 2005 (59)
April, 2005 (29)
March, 2005 (74)
February, 2005 (27)
January, 2005 (22)
December, 2004 (32)
November, 2004 (42)
October, 2004 (39)
September, 2004 (20)
August, 2004 (14)
July, 2004 (27)
June, 2004 (40)
May, 2004 (5)
April, 2004 (6)
March, 2004 (16)
February, 2004 (26)
January, 2004 (23)
December, 2003 (7)
November, 2003 (14)
October, 2003 (20)
September, 2003 (4)
Post Categories



Managed Windows Shared Hosting

A while back I blogged a few posts about creating custom timer jobs (here, here, here and here) and last week I pointed to a new MSDN Visual How To that shows how to do the same thing. There is also now a much more in-depth article I wrote that is now on MSDN that contains a lot of additional information about creating, deploying and debugging custom timer jobs.

» MSDN: Creating Custom Timer Jobs in Windows SharePoint Services 3.0

There are a few cool extra nuggets in this article that I want to point out.

  • The scenario I walk you through is not terribly "production" common, but rather something people like me need when teaching or presenting on SharePoint. We all know that many things in SharePoint requires application pool recycles. The part that's a pain is the warm-up time for the application pool (not a SharePoint issue, it's just an aspect of ASP.NET's JIT compilation of the pages). Microsoft first came out with something called the warmup scripts that are great in demos, but they are command line driven & you still have to manually recycle the app pool from the IIS manager or . My pal Spence has a killer utility that sits in the system tray which makes it very easy to recycle the app pool & warm up provided URLs: Application Pool Manager. What the timer job does is enable you to configure scheduled requests to specific site collections as shown in the article. It doesn't replace Spence's utility... I still use that. But it keeps your SharePoint site from "falling asleep." So, you can use this for your own SharePoint sites!
  • The job needed some way to store configuration information. There are plenty of ways to do this, but I elected to use the hierarchical object store that Maurice blogged about a while ago. There aren't many examples for this so here's another one for you.

The article doesn't have the downloadable source or built project so you can grab them from here:

» SharePointWarmupJob.wsp (in a ZIP)
» SharePointWarmupJob.Source.zip

[Update 6/2/2008 @ 7a] I've created a MSDN Code Gallery project for this project. This is where you'll find updates for this project: http://code.msdn.microsoft.com/SharePointWarmupJob

Technorati Tags: ,,
posted on Tuesday, April 15, 2008 5:37 PM

Feedback

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 4/16/2008 6:47 PM TJ
Gravatar Cheers for this AC, great article.

Can I ask, what kind of constructor/scope requirement you would use on a timer job that was to be activated at site collection level to perform work on that site collection, while avoiding it running on the front ends in a farm environment (running more than once wouldn't make sense)?

Finally what requirement would there have to be before a Timer Job was installed passing a service to the constructor? (wss_Administration as an example).

Much appreciated.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 4/21/2008 2:05 AM AC [MVP MOSS]
Gravatar TJ-
I don't follow either of your questions... sorry.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 4/29/2008 5:29 AM TJ
Gravatar After reading that my self, I can see why you couldn't understand it, not sure I do now :-) Sorry for my poor english.

Basically to cut that long explanation short, I was just seeking advice about the ctor.

A parameter of SPWebApplication or SPService is required. Is this just used to change the context/scope of where the job will run?

Cheers

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 4/29/2008 7:24 AM AC [MVP MOSS]
Gravatar TJ-
Yes.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/13/2008 12:49 PM Paul
Gravatar Hi,

Great information, this and the Visual How To helped me create the timer job I needed to run my workflow every 15 minutes.

A question that has come up:
Is there a way to have a timer job run every 15 minutes during every hour, but not anytime between say, :15 and :30?

We have a workflow that runs during those minutes and don't want this other workflow running at the same time.

Thanks,
Paul


# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/13/2008 9:14 PM AC [MVP MOSS]
Gravatar Paul-
Not sure... you might be able to get creative with the SPMinute schedule... but just not sure.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/15/2008 6:21 PM sted
Gravatar Is there a way to suspend or cancel a running timer job?

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/15/2008 9:38 PM AC [MVP MOSS]
Gravatar Sted-
Yeah... go to the Timer Job Defintions page in Central Administration and disable any installed timer job.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/19/2008 10:08 PM Paul
Gravatar Hi,
I've created a timer job that runs a workflow. ....for some reason... the timer job runs several times per minute. Although, I've set it to run ever 20 minutes or so. Can someone provide a sanity check here?

Here's the schedule:
SPHourlySchedule inversionSchedule = new SPHourlySchedule();
inversionSchedule.BeginMinute = 1;
inversionSchedule.EndMinute = 19;
inversionJob.Schedule = inversionSchedule;
inversionJob.Update();

And here's the entire method:


using (SPSite site = (SPSite)properties.Feature.Parent)
{

//Make sure jobs don't get added twice
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
if (job.Name == PUBLISH_JOB)
job.Delete();
}

//Create new jobs
PublishJob publishJob = new PublishJob(PUBLISH_JOB, site.WebApplication);

SPHourlySchedule publishSchedule = new SPHourlySchedule();
publishSchedule.BeginMinute = 1;
publishSchedule.EndMinute = 19;
publishJob.Schedule = inversionSchedule;
publishJob.Update();
}

Am I correct in assuming that the job will run once during the 1-19 minute time span?

Thanks,
Paul

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/19/2008 11:38 PM AC [MVP MOSS]
Gravatar Paul-
In the article I point to in this post (http://msdn.microsoft.com/en-us/library/cc406686.aspx), I explain that the Begin/End [Hour|Minute|Second] defines a window when the job *could* start. The SharePoint Timer service starts the timer job at a random time between the BeginSecond property and the EndSecond property. This aspect of the timer service is designed for expensive jobs that execute on all servers in the farm. If all the jobs started at the same time, it could place an unwanted heavy load on the farm. The randomization helps spread the load out across the farm.

Thus, if it's a long running timer job, it could run outsite the 20m window you specify in the code in your post.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 9/12/2008 6:14 AM Totoy Bato
Gravatar Hi Andrew,

thanks for the great post.
Ok, so i got same problem on "job.delete()", I'm assuming because my administrator doesnt have access to DB.. so I logged as DB admin, added the dbAdmin to sitecollection admin.. but to no avail.. any ideas?

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 9/12/2008 6:18 AM AC [MVP MOSS]
Gravatar Totoy-
"Same problem"... first time you're commenting so I'm not sure what your problem is. You need to be logged in as a SharePoint Farm Admin to delete jobs. Other than that, check the logs (event log & SharePoint logs) to get more info on your error.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 10/24/2008 9:17 AM Joe
Gravatar Hi Andrew,

Another great post!

I created a timer job that pulls data from an Oracle database and updates ListItems. The feature is deployed with Farm scope so that I didn't have to make it a hidden feature as you described in your article. My dev environment is a single server farm and everything works perfectly. However, the production topology has several WFE's and separate SSP box with central admin running on it. I chose to deploy it to the SSP and according to the log it deployed successfully and it shows up in the Timer Job definitions. However, the job never runs and the only indication that something is wrong is the following log entry:

Job definition --- has no online instance for service --- , ignoring.

I'm writing because I saw someone else had the same problem trying to use your example code:
re: Creating Custom SharePoint Timer Jobs 7/31/2007 2:03 PM dcp
and I'm thinking that it has something to do with the topology... any ideas?

-Joe


# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 10/24/2008 12:43 PM Wilson
Gravatar I found an video you presented in msdn
http://msdn.microsoft.com/en-us/library/cc427068.aspx
the video is not working and also I tried
http://www.microsoft.com/ms/msdn/office/2007OfficeVisualHowTos/WSS3CustomTimerJobs.wmv

It still does not work. Do you know where I can watch this video.

Thanks for the the great articl.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 10/24/2008 9:04 PM AC [MVP MOSS]
Gravatar Wilson-
The video link on the first one works just fine for me. I just now tested it.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 11/5/2008 3:20 PM AL
Gravatar Hi,

Great article; works just fine for us. We would like to know if there a place where we can find best practices for error-handling in Timer Job code? We're wondering that if we do not have proper error-handling in our custom timer job, we may compromise the execution of the Timer Service itself.

Any hint will be appreciated

AL

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 11/27/2008 3:26 PM Stevek
Gravatar Hi Andrew,

Great article. I created a timer job, and created a deployment wsp package for it. when I deploy it to sharepoint, it looks like it has been installed successfully, but it just does not run. When I attach the debugger to it, the break points are loaded, so the dll is attached to the process, but it just does not run. I've checked the logs and there are no error with the deployment. Do you know what I could be missing?

Thanks
Steve

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 11/28/2008 8:57 AM AC [MVP MOSS]
Gravatar SteveK-
Check the SharePoint ULS... turn on verbose logging.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 3/27/2009 4:08 PM Abhi
Gravatar Hi Andrew,

Great job. I have follwed your article and able to create/run the timer job succesfully. However, I am facing an issue related to event handler. When I add an item to list on Execute() of timer job, the ItemAdded event is not fired. If I add the item manually or thru other module, the event is fired. What might be the problem? Please help.

-Abhi

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/22/2009 11:48 AM Chantal
Gravatar Have a question regarding the WarmUp job. How does it work on a multi-front-end farm ?

Chantal

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 6/12/2009 12:41 PM Joe C
Gravatar First - great article and videos. Worked like a charm!

Wondering if you know of a way to run at intervals less than 1 minute apart? I have a job that we're going to need to run every 10 seconds or so over the next few months (don't ask!). I figure I can create 6 different solutions, setting them at different intervals, but I was wondering if there's a better / cleaner way.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 6/16/2009 4:00 PM AC [MVP MOSS}
Gravatar Joe-
Sorry, 60s increments are as low as you can go.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 6/16/2009 4:02 PM AC [MVP MOSS}
Gravatar Joe-
Little more info... you must schedule using one of the classes derived from the SPSchedule class: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spschedule.aspx

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 8/28/2009 5:43 PM Travis Pitford
Gravatar Andrew, I've looked at your articles and videos and would like to say great work. I wish I was a programmer and I'm sure I would appreciate it even more. However, I'm just a server guy trying to help out the HR department, and all I want to do is create a timer that runs a specific workflow everyday. Thats it. If anyone has an example and how to implement it that would be greatly appreciated.

Thanks,

Travis

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 8/31/2009 3:14 PM AC [MVP MOSS]
Gravatar Travis-
Not really all that possible as workflows have to be tied to a specific list item or document. You can't just have one run all on its own.

# re: not able to refresh the timer job 9/30/2009 6:49 AM aashita
Gravatar Hi,

First of all i would appreciate for providing such help. I have created a Timer job, but when i make any changes (not a huge one) it don't reflect in runtime. Please guide me how to clear the backlog..........and changes get reflect as soon as you deploy the DLL in GAC.

Please please please .............this become headache for me



# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 11/27/2009 2:11 AM Kenny
Gravatar I have downloaded and deployed AndrewConnell.TaskLoggerJob.wsp and SharePointWarmupJob.wsp to WSS3.0, but I don't see anything in Timer Job definitions. Nothing happens.

What could be the problem?

My thread to MSDN concerning the problem:
social.msdn.microsoft.com/.../7fa1d497-5aa3-4af...

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/20/2010 8:34 AM Sandra
Gravatar Hi Andrew,

I created a timer job and the feature is deployed in dev environment.When i try to activate this feature in Site Collection features ,it throws some error.I have listed the error below.But,it works on my VPC.Please get me some solution for this....

The EXECUTE permission was denied on the object 'proc_putObject', database 'FREEntEd_SharePoint_Config', schema 'dbo'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) etc..............



# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/22/2010 3:54 PM AC [MVP SharePoint]
Gravatar Sandra-
You must be a farm admin to add a timer job. I bet your VPC isn't setup with service accounts like production is.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 9/22/2010 4:09 PM keshav
Gravatar Hi,

how to run the custom timer job twice a week using the weekly schedule class in MOSS.


say on tue 12:00:00 and as well as on thu 13:00:00


not at only specific day.

Thanks in advance.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 9/24/2010 6:06 AM AC [MVP SharePoint]
Gravatar @Keshav - You're sort of answering your own question. A weekly schedule will only run once per week. What you need is to use daily and then add some logic to make sure that it only executes its logic on the days you want.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 10/15/2010 9:21 AM David Petersen
Gravatar Any hints on the error:

... has no online instance for service ... ignoring

I've seen a couple people post that they received this error with a timer job registering but not executing. I wondered if anyone had solved this? I've written many timers and this is the first time I have received this message.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 11/1/2010 10:42 AM Danny
Gravatar Hello,

I have a site scoped feature to create a cuastom job. Deleting job is no problem but when I try to create a new job like this:

SPSite rootSite = properties.Feature.Parent as SPSite;

OmWeekAlertJobDefinition gatherJob = new OmWeekAlertJobDefinition(JOB_NAME, rootSite.WebApplication, null, SPJobLockType.ContentDatabase);
gatherJob.Schedule = new SPOneTimeSchedule(DateTime.Now);
gatherJob.Update();

I get a access denied error.
Can anybody tell me why? I have tried with elevated privileges and with this:

SPWebService.ContentService.
RemoteAdministratorAccessDenied = false;

But no result



# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 11/4/2010 8:03 PM AC [MVP SharePoint]
Gravatar @Danny - Not possible the way you're doing this... you can't do this as a site/site collection scoped feature. They will be activated under the identity of the application pool which is typically not the same account as the farm account and thus doesn't have config DB write access. See this for more info: www.andrewconnell.com/.../6067.aspx

To prove this is the case, if you try to activate the feature via the command line while you're logged into an account with farm admin rights, you'll see it works. You shouldn't be able to do this via site/site collection scoped features; only Web App / Farm scoped features.

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/19/2011 3:31 PM khushi
Gravatar Hi there,

Thanks for the nice article. I have a quick question though.
Is there any way to determine or to catch an exception when the custom timer job is already in running state and Admin user is trying to run again. Anyway to tell Admin user that already an instance is running.

Thanks
Khushi

# re: More help on creating custom timer jobs (and a useful SharePoint site warmup tool) 5/20/2011 5:41 AM AC [MVP SharePoint]
Gravatar @Khushi - That's what the locking options are for... that keeps it from running multiple times.

Post Feedback

Title:
Name:
Email:
(email will not be displayed)
Url:
Comments: 
Please add 2 and 2 and type the answer here:    
All Comments Are Filtered & Moderated
Unfortunately comment spammers are just too effecient and are constantly dirtying up blogs with irrelevant and unwanted comments trying to improve their standing on search engines. All comments on this blog are moderated. I do not censor comments, but I don't approve comments with vulger language or those soliciting products. Most of the time comments are approved within a few hours of being submitted with the only exception when I'm traveling.

Why are you asking for my email address?
The only reason I'm asking for your email address, which isn't required to submit a comment, is to provide a gravatar if you've created an account for yourself and associated your email address with a small image. If you have a gravatar created for the email address you submit, it will appear next to your comment. Otherwise nothing will appear.

What is a gravatar?
A gravatar is a "globally recognized avatar." You can get more information about gravatars, as well as create your own for free, at www.gravatar.com. You can also view my gravatar here.


Copyright © 2003 - 2012 Andrew Connell
Creative Commons License 
This work is licensed under a Creative Commons License

 
SharePoint Training
Looking for SharePoint 2010 training for developers, administrators, power users, information workers, end users & web designers? Look no further! My company, Critical Path Training offers the best SharePoint training around! We offer public & private classes both as in-person instructor-loed hands-on classes and online classes. Check out our schedule and course catalog for all the ways we can get you going on your SharePoint path!