Thursday, July 28, 2011

Updating Timer Job Schedule

Some time we need to build and deploy a timer job with specific schedule say hourly or daily.
But for testing with the business or on your own , you don't want to wait for a day to see the change

Here is a simple console app code which you can use to change timer schedule for testing for any other reason

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace UpdateTimerJob
{
  class Program
  {       
   
static void Main(string[] args)
    {
      updateTimer();
    }

static void updateTimer()

{
  using (SPSite site = new SPSite("http://sp2010/sites/timer/"))
  {    foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
    {      if (job.Title == "WorkflowEscalation")
      {
        SPMinuteSchedule schedule =
new SPMinuteSchedule();
        schedule.BeginSecond = 0;
        schedule.EndSecond = 59;
        schedule.Interval = 5;
        job.Schedule = schedule;
        job.Update();


        Console.WriteLine("START UPDATING... ");
       }
     
Console.WriteLine("JOB: " + job.Title);
    }
  }
}
} }


Note: this need to run on the server; you can further modify this app to read site, title & schedule, then update accordingly

No comments: