The best Timer Job is a dumb Timer Job!

I have completed several projects using SharePoint Timer Jobs and for each project I am reminded how Timer Jobs can be a pain to implement and test. Yet they are often necessary to meet the requirements of the application. Here is what I have learned regarding Timer Jobs. Make them stupid! Rather than creating timer jobs that DO things, create Timer Jobs that simply tell something else to do the work.

Imagine that you use Microsoft Outlook to keep track of your meetings and tasks. You want to be reminded when you have something that needs to be done. This reminder comes to you on a specific schedule. When the reminder executes it does not do the work for you (if it does please let me know how you pulled that off), it simply tells you that something needs to be done. Your Timer Job can be the same way. It simply executes at a scheduled time and tells something else to do the work.

The next time you build a custom Time Job, try extracting the logic into another service that does the heavy lifting. This could be implemented as a workflow, a stored procedure or perhaps a custom web service. By taking the code out of the Timer Job, you can now update and debug your code independently, execute your code at your convenience, and you may even be able to reuse your code for other purposes.

I hope this tip helps someone else save time and frustration as it did for me.

2 thoughts on “The best Timer Job is a dumb Timer Job!”

  1. Eric,Nice article. Could you please throw some light on the "Performance Requirement" of a timer job that check the permission of some bunch of users (most probably be 50-60) per day on a web application that has approximately some 200 or so sites and sub-sites combined.ThanksKhushi

    Like

  2. Khushi, It sounds like you want to loop through each site and sub-site and record the permissions of these users somewhere? I think an lot of it depends on your hardware and what you would be doing with the data once you captured it.I would create a web part so you can trigger it through the UI as a site admin to test, and then if performance is not an issue, create a Timer Job to execute the same code daily.Another option if using SharePoint 2010 could be a PowerShell script, or even a command-line app executed on the server with a scheduled task. It all depends on the details of what your trying to accomplish.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.