Some months ago I needed to develop a custom timer job for a customer. That time I learned a lot from this post of Andrew Connell.
When the timer job ran in test, we used an SPMinutesSchedule. But after some time, the job needed to be deployed in production. So I had to change the code in the FeatureReceiver event to have a weekly schedule. So I came to the idea of developing an application page in which you can configure and reschedule job definitions.
You can download the feature here. (A small remark: when deploying the solution using the delivered setup, be sure to only leave the Central Administration web application checked).
You can access the application page from a custom section in the Operations page of the SharePoint 3.0 Central Administration.
The page looks like the following:
In the first section you can choose the web application for which you want to configure a timer job. The dropdown list in the Job Definitions section is populated with the job definitions running on the selected web application.
The third section is an idea I got from Andrews article. In general jobs run for a complete web application. But this feature makes use of the SharePoint object property bag so that you can configure a custom timer job to run for one or more site collections of the selected web application.
If you schedule a job for a specific site collection, you have to add some extra code within your custom timer job, otherwise it will continue running for the whole application:
Before you can use the U2U.SharePoint.Administration.JobConfigurationSettings class, you have to add a reference to the U2U.SharePoint.JobDefinitionConfigurator.dll, which is deployed in the 12\TEMPLATE\ADMIN\U2U.SharePoint.JobDefinitionConfigurator\bin folder:
Remark: This means that the option of running a job for a specific site collection doesn't apply to standard SharePoint jobs!!
In the 4th section you can choose a schedule. If the selected job is already scheduled, the next occurrence date and the current schedule is displayed:
You can also enable/disable a timer job.
If you want to learn more about developing custom timer jobs:
- read the MSDN article: Creating Custom Timer Jobs in Windows SharePoint Services 3.0
- look at the Visual How-To: Creating, Deploying, and Debugging Custom Timer Jobs in Windows SharePoint Services 3.0
both from andrew connell. Andrew, thanks for sharing your knowledge!
This feature contains resources: all strings can be translated into your language. The resource files are deployed to the 12\Resources directory and are retrieved using the SPUtility.GetLocalizedString. Thanks to Renaud Comté for helping me out with the resources.
You can read more about localization of strings here:
- Localisation des développements avec SharePoint
- Expression Builder et localisation