Andrew Connell [MVP MOSS]
1350 Posts |  39 Articles |  3385 Comments
.NET  |  MCMS  |  SharePoint  |  Office System
PDCBling
SharePoint Quick Links
Article Categories
Archives
Post Categories

View Andrew Connell's profile on LinkedIn

Add to Technorati Favorites

A few weeks back I posted about how you can create custom timer jobs for use in the latest release of SharePoint to perform scheduled tasks. However, considering there have been almost 40 comments to the post in the last three weeks, I figured the post needed some clarification (duh, ya think?).

The first thing you need to do is create a class that inherits from the Microsoft.SharePoint.Administration.SPJobDefinition class. To implement this class, you need to create a few constructors and override the Execute() method, like so:

   1:  namespace AndrewConnell.TaskLogger {
   2:    public class TaskLoggerJob : SPJobDefinition{
   3:   
   4:      public TaskLoggerJob ()
   5:        : base(){
   6:      }
   7:   
   8:      public TaskLoggerJob (string jobName, SPService service, SPServer server, SPJobLockType targetType)
   9:        : base (jobName, service, server, targetType) {
  10:      }
  11:   
  12:      public TaskLoggerJob (string jobName, SPWebApplication webApplication)
  13:        : base (jobName, webApplication, null, SPJobLockType.ContentDatabase) {
  14:        this.Title = "Task Logger";
  15:      }
  16:   
  17:      public override void Execute (Guid contentDbId) {
  18:        // get a reference to the current site collection's content database
  19:        SPWebApplication webApplication = this.Parent as SPWebApplication;
  20:        SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];
  21:   
  22:        // get a reference to the "Tasks" list in the RootWeb of the first site collection in the content database
  23:        SPList taskList = contentDb.Sites[0].RootWeb.Lists["Tasks"];
  24:   
  25:        // create a new task, set the Title to the current day/time, and update the item
  26:        SPListItem newTask = taskList.Items.Add();
  27:        newTask["Title"] = DateTime.Now.ToString();
  28:        newTask.Update();
  29:      }
  30:    }
  31:  }

As you can see, this job does nothing important but add a new item to a Task list every time it's executed. Now that you have the job built, you need to get it registered. Unfortunately the only way to do this is through code, but it sure would be one heck of a candidate for a custom STSADM command. Anyway, since we don't have that today, I like to use the feature activated & deactivated events to install/uninstall my custom jobs.

To do this, you have to create another class that inherits from the Microsoft.SharePoint.SPFeatureReceiver class and implement the FeatureActivated & FeatureDeactivated event handlers like so:

   1:  namespace AndrewConnell.TaskLogger {
   2:    class TaskLoggerJobInstaller : SPFeatureReceiver {
   3:      const string TASK_LOGGER_JOB_NAME = "TaskLogger";
   4:      public override void FeatureInstalled (SPFeatureReceiverProperties properties) {
   5:      }
   6:   
   7:      public override void FeatureUninstalling (SPFeatureReceiverProperties properties) {
   8:      }
   9:   
  10:      public override void FeatureActivated (SPFeatureReceiverProperties properties) {
  11:        SPSite site = properties.Feature.Parent as SPSite;
  12:   
  13:        // make sure the job isn't already registered
  14:        foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) {
  15:          if (job.Name == TASK_LOGGER_JOB_NAME)
  16:            job.Delete();
  17:        }
  18:   
  19:        // install the job
  20:        TaskLoggerJob taskLoggerJob = new TaskLoggerJob(TASK_LOGGER_JOB_NAME, site.WebApplication);
  21:   
  22:        SPMinuteSchedule schedule = new SPMinuteSchedule();
  23:        schedule.BeginSecond = 0;
  24:        schedule.EndSecond = 59;
  25:        schedule.Interval = 5;
  26:        taskLoggerJob.Schedule = schedule;
  27:   
  28:        taskLoggerJob.Update();
  29:      }
  30:   
  31:      public override void FeatureDeactivating (SPFeatureReceiverProperties properties) {
  32:        SPSite site = properties.Feature.Parent as SPSite;
  33:   
  34:        // delete the job
  35:        foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) {
  36:          if (job.Name == TASK_LOGGER_JOB_NAME)
  37:            job.Delete();
  38:        }
  39:      }
  40:    }
  41:  }

Now... to get it working, all you need to do is:

  1. Deploy the strongly named assembly to the GAC.
  2. Reset IIS (required for SharePoint to "see" the new timer job in the GAC).
  3. Create a feature specifying the receiver class and assembly that contains the event receivers.
  4. Install the feature.
  5. Activate the feature.

This sample timer job assumes it's running within the context of a WSS v3 site that has a list created with the Tasks list template in the root web within the site collection (or, just create a Team Site at the root of your site collection).

Once you activate the feature, it should show up on the Timer Job Definitions page in Central Administration / Operations. It won't appear in the Timer Job Status page until it's executed at least one time. Wait for five minutes or so (the schedule this sample is using) to see if it's running. You should start to see items showing up in the Tasks list in the root site in your site collection.

Here's a Visual Studio 2005 solution that includes everything you need to create a custom timer job. Note that I used the technique I described in this article to modify the Visual Studio project to create the WSP file for me:

» TaskLogger_CustomTimerJob.zip

Or, you can use this Windows SharePoint Solution Package (*.WSP) to deploy the prebuilt timer job used in this article (handles steps 1-4 above):

» AndrewConnell.TaskLoggerJob.zip (unpack the ZIP to get the WSP)

To deploy the WSP file, simply add it to the solution store using STSADM (using the following command) and then deploy it to the desired site:

stsadm –o addsolution –filename AndrewConnell.TaskLoggerJob.wsp

Note: if you plan to test the timer job attached in that article, please make sure you also uninstall it. I just realized I never uninstalled mine and my Tasks list had over 30,000 items in it from the last few weeks. Oops! :)

[Update 7/2/2007 @ 11p] Make sure you don't use visible Features when deploying your custom timer jobs as explained here in this post. The two code downloads in this article have been updated to reflect as such.

[Update 4/8/2008 @ 12a] A Visual How-To I created on the subject of creating custom timer jobs was recently posted on MSDN. You can get more info here.

[Update 5/1/2008 @ 730a] There is now an in-depth article on MSDN about creating custom timer jobs. If you have trouble please check this out as there is a ton of additional info here. Post: More Help on Creating Custom Timer Jobs

posted on Thursday, February 01, 2007 10:47 PM

Feedback

 re: Creating Custom SharePoint Timer Jobs 2/2/2007 8:30 AM Vijay
Gravatar Finally! the code :)
Thanks so much

 re: Creating Custom SharePoint Timer Jobs 2/2/2007 9:33 AM Swati
hi
1) I have deployed the wsp file and have activated the feature. But the feature is not visible in the Site Features. However, it is coming in the Timer Job Definition but after 5 minutes the task list is not populated

2)I have also checked the content database and there is no job shown in the schedule table(in content database)

Pls reply soon
Thanks in advance

# re: Creating Custom SharePoint Timer Jobs 2/2/2007 11:21 AM AC [MVP MCMS]
Gravatar Swati - Take a look at the feature that's deployed... it's not scoped at the Web, it's a site collection feature so you need to activate it from the Site Collection Features from Site Settings in the root web of your site collection. Also... stay out of the content database :)

 re: Creating Custom SharePoint Timer Jobs 2/3/2007 2:09 AM swati
Gravatar Hi
i have already activated the feature from the site collection features and when i try to activate the feature from site feature it give an error "Unknown Error " .
Pls Comment !!
thanx in advance


 re: Creating Custom SharePoint Timer Jobs 2/3/2007 5:16 AM Swati
hi before you gave the whole code I had done very much the same thing except for 2 things-
1-I had the scope at Web level
2-I had Accessed the site directly and not referred the content Databse
and it was not loading the task list after 5 minutes of feature activation (was this the reason as to it not working?)

Also i hav deployed your wsp file and i had activated the Feature at sitecollection level still it wasnt visible in site feature

Pls help

Thanks:)

# re: Creating Custom SharePoint Timer Jobs 2/3/2007 10:43 PM AC [MVP MCMS]
Gravatar Swati - It will never be visitble in the Site Features page, because my sample demonstrates only the site collection level. Just change the feature to make it work for a web. The sample WSP does work, I just tested it again.

# re: Creating Custom SharePoint Timer Jobs 2/4/2007 7:44 PM Kanwal
Gravatar Thank you very much for the sample code Andrew.
I have posted a link to your article on my blog.

 re: Creating Custom SharePoint Timer Jobs 2/4/2007 11:44 PM Suja
Gravatar Andrew
Thnx for the new blog ...very much in detail..

Is it possible to read the Sharepoint appln 's web.config file inside my job. My requirement is tht the timer job should connect to a database and get some values to populate a specific SP list.
As per my understanding the job runs as a separate entity.
If possible can you give me some hints.

Thnx
Suja


# re: Creating Custom SharePoint Timer Jobs 2/5/2007 12:59 AM AC [MVP MCMS]
Gravatar Suja - Your job is getting kicked off by OWSTIMER.EXE, the executable for the WSS Timer Service (Windows service). It will not be running within the context of SharePoint, hence why it passes in a GUID for the content database which you use to get context of a specific site. You'll need to either figure out a way to get the web.config of your site (possible, as you can get a reference to the content DB, then the site collection, I'm sure the web application, which I'd expect would expose a property for the web root, where you can access the web.config. Whew.. that's a mouthfull... you've got some work ahead of you :). Or, you could just put the setting in the registry or somewhere else.

 re: Creating Custom SharePoint Timer Jobs 2/6/2007 5:40 AM Vijay
Hi Andrew,

I was able to install the .wsp file using stsadm -o addsolution. I also did the deploy successfully using the Solution Management link. But now I am unable to activate it as the feature.xml file is not available! The ...Web Server Extensions\12\template\FEATURES location does not have a folder for this feature. I do not see this features in the Features list, not do I see it in the Timer Definitions screen.

Am I missing something?

Thanks,
Vijay

 re: Creating Custom SharePoint Timer Jobs 2/6/2007 5:53 AM Vijay
Gravatar Oops!! Spoke to soon! It's working like a charm :)

Thanks so much,
Vijay

 re: Creating Custom SharePoint Timer Jobs 2/9/2007 6:53 AM Donal
Gravatar Hi Andrew,

Thanks for the sample. I havent had a chance to play with this yet but one thing that confuses me is - how would you scope or paramaterize the job to run against a specific site collection. In your example the guid that gets passed to the Execute() is the guid of the content db - what I want also is the guid of the site collection the feature was activated on. Or would you use the base.Properties to store this.

Also are there any security implications in creating/deleting the job from the activation of a site collection feature.

Thanks

Donal

# re: Creating Custom SharePoint Timer Jobs 2/9/2007 8:52 AM AC [MVP MOSS]
Gravatar Donal-
Excellent question... you'll need to store this somewhere on your own. Best part: you can use the included property bag (SPJobDefinintion.Properties) to store your custom props.

Are there any security implications? Well, if it's a visible feature, then your site owners/site admins can add/remove timer jobs that are in assemblies in the GAC if the feature receiver adds it. The thing you want to be careful of though is if you don't want your site owners/admins doing this. In this case, I'd just make it a hidden feature that can only be activated/deactivated with server jockey via STSADM.EXE.

 re: Creating Custom SharePoint Timer Jobs 2/13/2007 7:55 AM Owe
Gravatar Hi,
Andrew.

Trying to deploy the example you supply to your article but having trouble getting the timer job going ...

Have successfully added the solution via Stsadmin (assembly is in GAC) and deployed globally in Central Administration. When I try to activate in Site Collection Features I get this "Unknown Error ". Looking into the application events tells me:

"Event Type: Error
Event Source: Windows SharePoint Services 3
Event Category: Database
Event ID: 5214
Date: 2007-02-13
Time: 13:45:51
User: N/A
Computer: WSS1
Description:
Insufficient SQL database permissions for user '' in database 'SharePoint_Config' on SQL Server instance 'WSS1'. Additional error information from SQL Server is included below.

EXECUTE permission denied on object 'proc_putObject', database 'SharePoint_Config', schema 'dbo'.

Do you have any suggestions on how to grant access to the database for the timer job assembly?

Thank you very much!

# re: Creating Custom SharePoint Timer Jobs 2/13/2007 8:53 AM AC [MVP MOSS]
Gravatar Owe - This indicates that the user account you're logged in under doesn't have admin rights to your SharePoint environment... make sure you are logging in with an account with admin rights to your SharePoint environment.

 Reading Web.config from timerjob. 2/16/2007 4:30 AM Ludwig
Gravatar To access the web.config from within a timerjob use the following code:

Configuration config = WebConfigurationManager.OpenWebConfiguration("/", "Sharepoint - 80");
string value = config.AppSettings.Settings["keyName"].value;

Have fun.




 re: Creating Custom SharePoint Timer Jobs 2/16/2007 7:42 AM Vijay
Gravatar Hi Andrew,

This might sound crazy, but I modified the code to
a. write to a different Task's list. But it just seems to ignore it.
b. I then removed the DateTime value and replaced it with a static value - this also did not work. I see the same datetime in the Title.
c. I then removed the insert and made it an update - this worked as expected - but it still continued to update the DateTime instead of the static value!

I ensured there were no mutliple copies of the .wsp, I also ensured the the DLL is getting deleted after uninstall and new version comes after install. I did a iisreset - but no change in behavior. This is driving me crazy!
Hope you can help!

Regards,
Vijay

 re: Creating Custom SharePoint Timer Jobs 2/16/2007 8:55 AM owe
Gravatar What admin rights is needed explicitly?

The user I am logged on (I am actually also logged on to the win server) is member of Builtin\Administrators group on the server, is set to Site Collection Administrator (for the site I try to activate the job for) and belongs to Site Owner group.

Also, the account has access to Sharepoint_Config database trough Builtin\Administrators which belong to DB Role: db_Owner.

Could there be some other setting I have to do?

Thanks.

# re: Creating Custom SharePoint Timer Jobs 2/16/2007 9:08 AM AC [MVP MOSS]
Gravatar Ludwig-
Thanks for posting that snippet for others.

Vijay-
I've seen this before... I had to keep incrementing the versions of the assembly when I was tweaking my code. I'm not sure if there is some caching going on, or if it's a bug... either way, I'll post back my results.

Owe-
That error is telling you that you don't have access to the config or content database. I don't remember what permissions you need offhand... check the Admin & Setup newsgroup.

 re: Creating Custom SharePoint Timer Jobs 2/16/2007 10:23 AM Gaetan
Gravatar many thanks for the post. Very clear and useful.

I have a windows app. which synchronizes users SP account with our users directory (using form auth. and a custom membership provider). I'm currently trying to replace this winddows app. with a SPJob (trying to do things the sharepoint way).

To be able to use all Membership related objects in my code, I added this portion in the app.Config file :

<system.web>
<authentication mode="Forms" />
<membership defaultProvider="AGDProvider">
<providers>
<clear />
<add name="AGDProvider"
connectionStringName="AGDProvider"
applicationName="MOSS2007 Membership Provider"
/>
</providers>
</membership>
</system.web>

you said the job was launched by the owstimer.exe.
So what file is owstimer.exe looking for when in thecode we use "ConfigurationManager.AppSettings[...]" ?

In what file should I put the membership configuration xml so that the job and owstimer.exe can use all Membership related objects ?

Gaetan.

# re: Creating Custom SharePoint Timer Jobs 2/19/2007 3:51 PM AC [MVP MOSS]
Gravatar Gaetan-
I suspect you'll need to add into your custom timer job to read from a specific configuration file... not adding it to some config file the OWSTIMER.EXE process is already reading from.

 re: Creating Custom SharePoint Timer Jobs 2/20/2007 10:10 AM Eric
owe -
Try activating the feature from the stsadm tool rather than through the web interface. I was having the same permissions problem and this worked for me.

 re: Creating Custom SharePoint Timer Jobs 2/21/2007 7:28 AM Alex
Gravatar Hello.

Got a problem with Timer Jobs, can't resolve... I have my Job, that inherits SPJobDefinition, some constructors, overrided Execute(Guid targetInstanceId). I don't have feature, just register new job from inside a webpart. After registering it, I can see it in SP Central Administration, Last run time is changing just like it should according to the Schedule I pass to my job, but nothing happens. If I run Execute method from constructor, the things should happen are happen, no problems, so - no error in logic... but why don't they happen on schedule?

# re: Creating Custom SharePoint Timer Jobs 2/21/2007 8:17 AM AC [MVP MOSS]
Gravatar Alex-
Sounds like you either have a problem with the schedule or SharePoint isn't aware of it. Make sure you recycle the timer service, or even IIS... also make sure you give the job enough time to run. For example, I'd set a schedule for it to run every 2 minutes from 0-59 just to make sure its working.

 re: Creating Custom SharePoint Timer Jobs 2/23/2007 10:10 AM yongbo
Gravatar Hello, I made a TestTimer, an installer, and a feature. The Execute method just write a line to Event Log. I got an error: "TestTimer cannot be deserialized because it does not have a public default constructor" in the event log. But I do have default constructor, and three other constructor. My questions also include: 1) Do I need Manifest.xml? 2) Do I need all constructors as you have in your example? 3) I could not find Sharepoint Timer Service or OWSTimer.exe running, is that part of reason of failure?
Thanks.

# re: Creating Custom SharePoint Timer Jobs 2/23/2007 11:03 PM AC [MVP MOSS]
Gravatar Yongbo-
The error you describe is definately because the class doesn't contain a default public constructor. If you're sure your assembly has it, I'd suggest either (1) removing it from the timer job definitions, then incrementing the assembly version, then reinstall and test or (2) recycle IIS and the WSS Timer Service as I'm guessing the assembly is getting cached.

 re: Creating Custom SharePoint Timer Jobs 2/26/2007 10:12 AM Yongbo
Gravatar Thanks! Andrew, You are right that the assembly is cached, I thought it was removed when I iisreset and recycle application pool, but it was not. Maybe I did not do it properly. Finally after I restart the server, the problem is resolved. Thank you very much for your help. Can you give me hints on how to recycle IIS and WSS Timer Service?
Thank you again for your time.

# re: Creating Custom SharePoint Timer Jobs 2/26/2007 10:18 AM AC [MVP MOSS]
Gravatar Yongbo-
Resetting IIS won't do it, because the timer service runs outside of the web services... hence why when debugging you need to manually attach to the WSS timer service (OWSTIMER.EXE). To recucle that service, just open the Windows Services applet and recycle the service using the toolbar.

 re: Creating Custom SharePoint Timer Jobs 3/5/2007 11:12 AM Yongbo
Thanks! The problem was: I have a timer job which runs a program deployed to GAC. After I change the program, deploy it to GAC, the timer job does not grab the updated one, instead, still runs the old one. I figured that the timer job has its own copy of the program and runs it every time triggered, instead of grabing it from GAC. That's why I need to restart the timer service. I actually resolved the problem by restarting the Window Sharepoint Timer Service.

Another problem I have now: The EndSecond of my SPMinuteSchedule is set to be 59, as you did in your example. I am not sure if this is the reason that the timer job stops executing after the one minute, even though the job is not finished. I want my timer job finish every time it's got triggered. Should I set EndSecond be more than 59?

I appreciate your time and reply!

# re: Creating Custom SharePoint Timer Jobs 3/5/2007 4:41 PM AC [MVP MOSS]
Gravatar Yongbo-
No... 59 indicates you want it to run up to the 59th second of every minute. Say for example you only wanted a job to run in the first quarter of every hour... you'd set the start time to 0 and the end time to 15.

 re: Creating Custom SharePoint Timer Jobs 3/6/2007 11:03 AM Yongbo
Right. It's not a problem if the job takes less than one minute. What if the job needs more than 59 seconds, say 100 seconds, to finish, how do I set the schedule so that each time the job is started, it finishes no matter how long the job is going to take? I guess we might not be able to schedule a 2-minute timer job runs every 5 minutes. Thanks!

 re: Creating Custom SharePoint Timer Jobs 3/6/2007 4:30 PM Gary
Andrew,

Great, detailed article. Also, I had the config database error trying to activate via the web interface, even though I'm logged in as an admin with rights to pretty much everything. But I was able to successfully activate via stsadm, and then the timer job worked like a charm.

Thanks Again!
Gary

# re: Creating Custom SharePoint Timer Jobs 3/21/2007 4:27 PM Michael
Gravatar Andrew,
Thank you for this post. The code works great and is exactly what I needed to get my job started. I am running in to a situation with the SPDailySchedule. Is there any information out there as to how to set that up?

I tried to set the .Begin/.End Hour, Minute, Second properties with 0/24, 0/59, 0/59 and set the NextOccurance property to DateTime.Now.AddMinutes(30). The first error I received was that the Datetime hour, minutes, seconds were not correct when I tried to activate the feature. So I removed them and left the NextOccurance property with the datetime value indicated above. It activated fine, but now I am not seeing that it executed.

Do you know where some information is on this schedule and how to set it up? I checked MSDN and it doesn't have much info other than the members of the class.

Thank you for any assistance in advance.

 re: Creating Custom SharePoint Timer Jobs 4/28/2007 7:00 AM Deenu Varghese
Gravatar This topic really helped. I didnt find any other documentation which explained the same.



 re: Creating Custom SharePoint Timer Jobs 5/1/2007 10:25 AM Matt
Gravatar Andrew,

I think I'm a little confused, I was able to downloaded your sample solution and build it with no problems, however I do not see my assembly in the GAC when I reset the IIS, or I dont see any reference to it int he features list or any other place taled about. Am I missing a deployment step other than just just bulding the process.

Any help is very much appreciated!!!

Matt

# re: Creating Custom SharePoint Timer Jobs 5/1/2007 10:41 AM AC [MVP MOSS]
Gravatar Matt-
You usually have to give it a bit of time... doesn't show up immediately. It has to run the first time for it to appear.

 re: Creating Custom SharePoint Timer Jobs 5/1/2007 11:21 AM Matt
Gravatar Well I was messing around with some things because I am not familar with accessing features throught the object model, anyways I added an install.bat tot he project which i used to deploy my workflows to the GAC. The .bat file calls the gacutil, and stsadm which deploys it to the GAC. This method allowed me to deploy it to the GAC correctly and I now see it in the timer job defintitons page on my SP central admin page. However when i log into the content database and try to locate the feature from the site features page under the admin tools, it does not appear, nor are any tasks getting created as of yet. Am I going about this the wrong way because I have been working on this for a couple hours now and nothing has worked shown up untill I added the install.bat.

Thanks a million for the quick response!!!
Matt

# re: Creating Custom SharePoint Timer Jobs 5/1/2007 8:55 PM AC [MVP MOSS]
Gravatar Matt-
The WSP should have certainly be deploying the assembly to the GAC... that's what you wantt o look at in terms of a solution. Creating a batch file to call GACUTIL is not a solution as it shouldn't be necessary. Not sure what's wrong... sorry.

 re: Creating Custom SharePoint Timer Jobs 5/2/2007 11:14 AM Matt
Gravatar Andrew,

Do you happen to run: "stsadm –o deploysolution –name <template_name>.wsp -allowgacdeployment" after you run the addsolution command. The add solution command alone never did anything, but once I ran the deploysolution command I was able to see it in the GAC. However even know I got it to deploy correctly it still is not functional. I wanted to mention that I am using WSS not MOSS, maybe that is a factor??? Lastly what did you use for your resurce for this topic, unfortunately this is the last functionality I needed in my project. I have bought and read both of the books you contributed to and niether addresses this problem.

Thanks,
Matt

# re: Creating Custom SharePoint Timer Jobs 5/2/2007 5:59 PM AC [MVP MOSS]
Gravatar Matt-
Well yes, you have to depoy the solution... adding it does nothing but add it to the solution store. Timer jobs aren't just a MOSS thing, they are a WSS thing. Unfortunatley there are hardly any resources for timer jobs. I've been meaning to augment the MSDN wiki SDK with some of my findings. There isn't anything in the books either... had to just use Lutz's Reflector and do some low level reflection and exploring of the object model to figure this out.

 re: Creating Custom SharePoint Timer Jobs 5/3/2007 3:57 PM Matt
Gravatar Andrew,

Thanks you very much for all your help, I'm finally starting to put all of the pieces together. I have a couple last questions, First is what is the actual deploy string you use to deploy your wsp? You can reference my last post for what i have so far, but you need to specify ether immediate, local or a time reference on the end of the string and I'm not sure what is the correct one. Second question is there any other steps neccessary to deploy the .wsp other than the correct stsadm deploy statement? Lastly, how do you deploy your solution when your in Visual Studios, do you just copy over the newly created .wsp file to the proper folder and then run the Addsolution and deploysolution commands accordingly?

Thanks again Andrew, I greatly look forward to any of your future posts!!!

Matt

# re: Creating Custom SharePoint Timer Jobs 5/3/2007 4:07 PM AC [MVP MOSS]
Gravatar Matt-
#1 - I typically don't deploy using the command line, I use the browser UI. Run STSADM.EXE -help deploysolution to get all the available switches or browse to Central Administration -> Operations -> Solution Management to deploy/retract/remove solutions (you can't add via the browser). For the command line, -local deploys it immediately (just like -immediate) or you can specify a time you want to schedule the deployment.

#2 - Nope... add the solution to the solution store and deploy. If you are deploying a feature, you'll probably have to go activate it. All a solution does is get the files to the appropriate spots on the server.

#3 - Today it's all manual copying files around. But if you look at the post, towards the end I link to an article on my blog showing how I build them in VS2005 with makecab.exe and MSBuild. In that article, I reference a post by Tony Bierman that takes it even futher, creating even more MSBuild target options for deployment. I suggest you read up on that.

More on #3 on my blog sometime in May (I hope... where's the time going?).

 re: Creating Custom SharePoint Timer Jobs 5/4/2007 3:59 PM Matt
Gravatar Andrew,

After fighting threw a number of problems I found out my problem was the Windows SharePoint Services Adminstration service was not started in services.msc. By default this services is not started on Windows Server 2003, I just wanted to post this to save others time over this silly issue.

Thanks a million for all of your help, I couldnt have gotten this far without it!!!

Matt

# re: Creating Custom SharePoint Timer Jobs 5/4/2007 5:18 PM AC [MVP MOSS]
Gravatar Matt-
There's an STSADM command called EXECADMSVCSJOBS that manually fires any queued jobs off... including the one you're trying to do in this case. This is useful if you don't want the service running (such as on a virtual machine).

 re: Creating Custom SharePoint Timer Jobs 5/6/2007 7:06 PM Chan
Gravatar HI Andrew,
I downloaded the your TaskLoggerJob wsp and tried to add it to the solution using stsadm, But I get the follwing error message

Object Reference not set to an instance of an object.

Do you know anything about this?
Any help is greatly appreciated.

Thanks
Chan

# re: Creating Custom SharePoint Timer Jobs 5/6/2007 9:05 PM AC [MVP MOSS]
Gravatar Chan-
Sorry, not enough info to troubleshoot.

 re: Creating Custom SharePoint Timer Jobs 5/7/2007 1:37 AM Chan
Gravatar Thanks ,

I fixed the problem !
The user i was logged onto the share point server didn't have dbo access to the sql server content and admin databases.

Thanks again
Chan

 re: Creating Custom SharePoint Timer Jobs 5/8/2007 11:46 PM Sathya Narayanan
Gravatar Hi Andrew,
Thanks for such a nice article!

I have tried the above code, but i am getting error. When i activate my feature and check in timer job status page of central admin, i can see the "Task Logger" installed with status "Failed". Any idea about this problem?

 re: Creating Custom SharePoint Timer Jobs 5/10/2007 2:27 PM Matt
Gravatar Andrew,

I'm sorry Andrew I just don't get what is triggering the Execute method, It doesnt seem to be inherently called anywhere in your code. I created my own job program that mimics your sample and it works fine, but when I start adding my custom code it seems to break it. Any information on how the method is actually getting called shaould be more than sufficient.

Thanks a bunch!

Matt

 re: Creating Custom SharePoint Timer Jobs 5/10/2007 2:36 PM Matt
Gravatar Duh I'm a retard, i just realized I removed the Override from the function definition for testing and forgot about it....

Sorry for wasting you space and time.

Matt


 re: Creating Custom SharePoint Timer Jobs 5/10/2007 6:53 PM Pankaj Sabnis
Gravatar I am looking at the SPDailySchedule class and have a question. I can schedule a timer job to run at a specified start and end time. But there is no way I can specify a date. Say I want a job to run from 1st June to 15th June at 1:00 am in the morning, how can I go about doing that. First of all, is it possible?

 re: Creating Custom SharePoint Timer Jobs 5/21/2007 7:42 PM calcock
Gravatar I've installed this with a scope="Farm". It shows up in the "Timer job definitions" list, but not in the "Timer job status" list as it never fires. Nothing in the event logs or the wss log files to indicate whether it tried to fire or not (got an error, failed in some way, etc.). Any suggestions on determining what the problem could be?

Tks.

 re: Creating Custom SharePoint Timer Jobs 5/30/2007 5:49 PM 7bergen
Gravatar Thank you for your article. Very helpful!

I have a really weird story; therefore I put it in here.

By activating the timer feature trough the user interface I receive a 404 access denied error. Also the feature page was not showing that the feature was activated; however, the timer job was activated in the 'background'. After some debugging I found out that it was file path permission issue, as per following error message:

Access to the path 'C:\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config\bd189eb6-92d0-4ca5-87b0-770f542e3f0a\cache.ini' is denied.

Solution: If you give WSS_WPG user account full permission to the config folder (as per above file path) the error will disappear!

Is this not a weird situation? Are there any comments?

 re: Creating Custom SharePoint Timer Jobs 6/1/2007 9:52 AM Brian
Gravatar Nice article Andrew, but I got one question...

Do you have to create a wsp, file or can you install this as a feature? It seems like creating a wsp in quite the hassle compared to just installing a feature.

-Brian

# re: Creating Custom SharePoint Timer Jobs 6/1/2007 9:58 AM AC [MVP MOSS]
Gravatar Brian-
WSP's are just used for deployment... just like an MSI. You can install something manually, it's just easier using an installer. Yes, you can manually deploy the Feature, add the assembly to the GAC and activate the Feature. A hassel? I sure don't think it's a hassel.

 re: Creating Custom SharePoint Timer Jobs 6/1/2007 11:18 AM Brian
Gravatar Ah, ok I think I misunderstood at first. Thanks for the quick reply. So is the feature I install whatever class I have that inherits SPFeatureReceiver?

-Brian

# re: Creating Custom SharePoint Timer Jobs 6/1/2007 12:04 PM AC [MVP MOSS]
Gravatar Brian-
The Feature is simply a vehicle to install the timer job... this is done from code, which used the FeatureActivated event receiver to call this code.

 re: Creating Custom SharePoint Timer Jobs 6/21/2007 1:13 PM jayman
Gravatar Andrew,
Thank you for your article, it helps me a lot !
for sure, got a question for you : i have a web application containing 3 sites collections. 2 of them are on the same wss_content : wss_content1, and the last one is on another wss_content:wss_content2.
I expected the execute() method fire twice, because of the guid contentdb as a parameter, i scheduled the job once in a day. the job count items in document library and create a excel file and add it in another document library.
The problem is when i open the excel file, i only have the items count for wss_content1 the 2 first days, and the 3rd day i got the items count à wss_content2, the 4th day wss_content1 and the 5th day wss_content2.
Have you got a explaination for this ?
How can i do to have in the excel of a day, the count item of wss_content1 and the count item of wss_content2. any idea ?
thanks in advance.

 re: Creating Custom SharePoint Timer Jobs 6/24/2007 8:00 AM Renatas
Gravatar Hi,

nice article. I also had a problem the same as Alex. Job was registered and last run time correctly updated but job itself was not executed - that is "nothing happens".
So restarting OWSTIMER helps. After restarting the timer scheduled job executes fine.

 re: Creating Custom SharePoint Timer Jobs 6/25/2007 2:12 AM HV
Gravatar Thank you Andrew for such a nice post

I have a timer job feature.
I have used msbuild script to deploy/delete those features to farm.

I use the following commands in sequence to remove a solution (.wsp) from a site:

stsadm -o retractsolution -name Journaling.wsp -immediate
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name Journaling.wsp -override
stsadm -o execadmsvcjobs

Retraction step works fine. But when it tries to delete the solution it says:

"The solution cannot be removed when a job is scheduled or running"

Though there are no such jobs running.

Any idea on why is it displaying such a message? Any solution to this?


# re: Creating Custom SharePoint Timer Jobs 6/26/2007 12:20 AM AC [MVP MOSS]
Gravatar HV-
Did you try refreshing IIS after the restraction? I wouldn't be surprised if the assembly was still in the cache.

 re: Creating Custom SharePoint Timer Jobs 7/13/2007 11:30 AM Yash Desai
Gravatar This article should go up in the Microsoft docs!

Thanks Andrew.

 re: Creating Custom SharePoint Timer Jobs 7/13/2007 3:28 PM Yash Desai
Gravatar Hi Andrew,

How would I have to set the Start and End times if I want the job to run at say 3pm everyday.

And can you explain it in detail?

thanks in advance.

# re: Creating Custom SharePoint Timer Jobs 7/16/2007 11:10 AM AC [MVP MOSS]
Gravatar Yash-
Just set the schedule to run between 3p-3:01p and run every minute.

 re: Creating Custom SharePoint Timer Jobs 7/17/2007 10:15 AM burnett
Gravatar hi,AC,this article is very useful to me.but i have a problem when i deploy this feature to the "Timer Job Definitions" for more than once.when i changed some feature in the class and build it to wsp file,when i deploy it to the server ,i find that the behavior doesnt change ,and the feature is the initial feature(the first time i deployed).
thoes bellow are all the commands i used.
============
stsadm -o retractsolution -name EventCheckTimer.wsp -immediate
stsadm.exe -o execadmsvcjobs
stsadm -o deletesolution -name EventCheckTimer.wsp -override
stsadm.exe -o execadmsvcjobs
stsadm -o addsolution -filename EventCheckTimer.wsp
stsadm -o deploysolution -name EventCheckTimer.wsp -immediate -allowgacdeployment -force
stsadm.exe -o execadmsvcjobs
======
i have tried out many ways .just as restart timer service, restart iis,even restart windows,but it seem to be helplessT_T

# re: Creating Custom SharePoint Timer Jobs 7/18/2007 8:33 AM AC [MVP MOSS]