SharePoint: timer jobs and history and status

History in SharePoint jobs

Timer jobs are a convenient way to perform background tasks in SharePoint. This article organize some facts about the history of the timer jobs. The following facts are true for SharePoint 2010, but most of them should be valid for other versions of SharePoint.

History of a timer job is a collection of entries that contain the information about:

  • Job’s name
  • Job’s start time
  • Job’s end time
  • Job’s result (status code)
  • Some UUID’s to identify server, web application, job, service etc.

Those information allow us to see some abnormalities in the duration or status of the job should they occur one day.

History entries are only written for jobs that has finished executing. This means that there are no history entries for the jobs currently running. One of the consequences is that you can’t use history to list the jobs that are running but has not finished yet.

Where and how long is timer job’s history stored

According to MSDN documentation, job history is stored for 7 days. The static class SPDeleteJobHistoryJobDefinition provides some configuration for the job history via Object Model properties, including the setting of number of days the history is stored.

In SharePoint 2010 history entries are stored in central administration’s database table TimerJobHistory (see fig. 1). While it’s considered a bad practice to access SharePoint contents directly via SQL, this might be the easiest way for some analytic purposes like exporting the history to CSV file.

SharePoint 2010 – timer jobs history in SQL Server database

SharePoint 2010 – timer jobs history in SQL Server database

The proper and supported way to access data about job history is via the SPJobDefinition‘s property called HistoryEntries. The next section show some simple example of this property.

Example: When was the last time a job was running?

The following example obtains the information about the time of last successful run of a timer job. It could be written more concisely, but it’s aim is to show how to iterate timer jobs in SharePoint’s Object model and use HistoryEntries property. Comments are added to further explain the subject.

Timer Job history can also be managed via PowerShell if you prefer.

If you are interested in accessing information about the currently running jobs rather than those from the past, you might also want to read SharePoint: list running timer jobs (C#). Good luck!