Partager via


Forcing Execution of MOSS Timer Jobs

Introduction

MOSS relies heavily on timer jobs for a number of its functionality areas. Timer jobs execute on a fixed schedule, and no matter what, they will execute on the schedule that has been assigned to them. What if you want to get a particular job executed at your will? This article explains how.

Changing Schedule of Timer Jobs

If you want to force execution of a MOSS timer job, you unfortunately can't do it. Because every timer job has a fixed schedule. There are three types of schedules: Minutes, Hourly and Daily. Although you can't really force execution of a job, you can definately change the execution schedule of a timer job and in most cases, it'll give you what you're looking for. For example, Usage Analysis job is a daily job. It executes exaclty once per day. If, for example, you want this job to be executed immediately, you can change the schedule of this job from "Daily" to "Minutes". The schedule of all built-in MOSS timer jobs can be changed using stsadm command setproperty. To change the schedule of the usage analysis job such that it executes every five minutes instead of every 24 hours, following command can be used:

stsadm -o setproperty -pn job-usage-analysis -pv "Every 5 minutes".

The property names for all other built in timer jobs are given below:

 job-change-log-expiration
 job-dead-site-delete
 job-diskquota-warning
 job-immediate-alerts
 job-recycle-bin-cleanup
 job-usage-analysis
 job-workflow
 job-workflow-autoclean
 job-workflow-failover

If you have a custom timer job definition and you want to change its schedule, the only way that I can think of is by using the object model. There is no stsadm command for changing schedule of custom jobs. Following is a sample that shows how shedule of a custom job definition can be changed to a per minute schedule.:

            SPSite siteCollection = new SPSite(https://site.url.com);
            SPWeb web = siteCollection.OpenWeb();
            SPFarm farm = siteCollection.WebApplication.Farm;
            SPWebApplication webApp = siteCollection.WebApplication;
            //SPTimerService timerService = farm.TimerService;
            foreach (SPJobDefinition jobDef in webApp.JobDefinitions)
            {
               // if (jobDef.WebApplication == siteCollection.WebApplication)
                 //   Console.WriteLine(jobDef.Title);
                 if (jobDef.Title == "Usage Analysis")
                    {
                        jobDef.Schedule = new SPMinuteSchedule(); 
                        jobDef.Update(); break;
                    }
            }

Conclusion

If you want to execute a MOSS timer job that only executes after a long period of time, you can do so by changing the schedule of the job. If the job is a biult-in job, the schedule can be changed using stsadm. If the job is a custom job, the only possible way is by using the MOSS SDK.

Comments

  • Anonymous
    June 01, 2009
    PingBack from http://uniformstores.info/story.php?id=2929

  • Anonymous
    December 03, 2009
    what about running this? stsadm -o execadmsvcjobs

  • Anonymous
    December 03, 2009
    It is largely believed that stsadm -o execadmsvcjobs executes all timer jobs. Not true. This command only runs administrative timer jobs that SharePoint creates for certain tasks and then runs whenever resources are available. For example, when you create a new SSP, there are administrative timer jobs that complete the provisioning. Similarly, when you create/extend a web application, timer jobs are created to do the same on all servers in the farm.

  • Anonymous
    April 13, 2010
    rather use net start/stop SPTimerV3 after you change a schedule

  • Anonymous
    March 17, 2011
    I sometime used "stsadm -o execadmsvcjobs"  to accelerate InfoPath template form upload and install at central admin.

  • Anonymous
    May 11, 2015
    stsadm -o execadmsvcjobs Executes all administrative timer jobs immediately instead of waiting for the timer job to run.