3

Is there a way to check for the status of a timer job, I need to know the last time it executed and its status, that it run correctly?

3

You could try something like this:

SPWebApplication w = GetYourSPWebApplicationFromSomewhere();
foreach( var e in w.JobDefinitions["YourJobName"].HistoryEntries)
{
    var jobStatus = e.Status;
    var startTime = e.StartTime;
    // TODO: Do your stuff with Status and StartTime
}

var sc = SPFarm.Local.Services;
foreach (var e in sc["YourServiceName"].JobHistoryEntries)
{
    var jobStatus = e.Status;
    var startTime = e.StartTime;
    // TODO: Do your stuff with Status and StartTime
}
1

While Kjetil Gullen's and Paul Schaeflein solutions will work fine for completed tasks (succeeded or aborted for some reason), the entries for the currently running jobs are not yet present in the JobHistoryEntries.

You can include running jobs in your check by using the RunningJobs property of SPService (for all jobs running under a SharePoint service) or SPWebApplication (then the scope is limited to jobs running in web app). Code example for the first case is in StackOverflow's answer to "Check if a SharePoint timer job is currently running", and for the second case in SharePoint: list running timer jobs (C#) article.

0

SPWebApplication.JobHistoryEntries

SPService.JobHistoryEntries

  • 1
    example of working code you have? – Luis Valencia Mar 30 '12 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.