TwitterLinkedInBlog

Tuesday, October 13, 2009

SP2007 - Why is my timer job executing twice?

I have seen many blog comments referring to a developer's timer job executing twice, but no solutions. It's happening to me and I'm determined to figure out why this week. I'll post the solution when I find it.

Newest Update: From the comment below:
Clemens said...
I just found:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spjoblocktype.aspx
you should use SPJobLockType.Job instead of SPJobLockType.ContentDatabaseJob in the Jobs constructor.
SPJobLockType.ContentDatabaseJob executes for every DB, the other only once per mashine

Older Update: Thanks to this blog entry...
rafelo: SharePoint Timer Jobs Running Multiple Times
...I looked through the logs and the job was running once for each content database! I verified the guids of the content databases by going to Central Administration > Application Management > Content Databases and hovering over the link to each. The guid is in the query string (DatabaseId).

Notice the signature of the method:
public override void Execute(Guid contentDbId)
{
...
If (mySiteCollection.ContentDatabase.Id.Equals(contentDbId))
{
... // put your code here and it will only run once for the targeted site collection.
}
...
}

1 comment:

Clemens said...

I just found:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spjoblocktype.aspx

you should use SPJobLockType.Job instead of SPJobLockType.ContentDatabaseJob in the Jobs constructor.

SPJobLockType.ContentDatabaseJob executes for every DB, the other only once per mashine

Regards