1

Below is our server topology

3 WFEs 2 App Servers 1 DB server

Now, I would like to write a custom timer job that should run only on the specific application server("APP1").

SPJobdefinition does not allow me to do this as there is no lock type for server.

Shall I use the SPServerJobDefinition class to do this? If so, any sample code would help.

  • hi community, any help? – Karthikeyan Nov 7 '12 at 10:25
1
namespace DotnetFinder
{
    class myTimerJobDef : SPServerJobDefinition
    {   
        public myTimerJobDef()

            : base()
        {

        }

        public myTimerJobDef(string jobName, SPServer server)

            : base(jobName, server)
        {
            this.Title = jobName;
        }


        public override void Execute(SPJobState _jobState)
        {

            Logs.LogMessage(Logs.Log_INFO, Logs.Log_severity_verbose, "Timer Job - Server specific is running on ");
        }
    }
}

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            DotnetFinder.myTimerJobDef myJob = new DotnetFinder.myTimerJobDef("Server Timer Job", SPFarm.Local.Servers["myServer"]);
            // here you can assign the schedule as per your requirement. I have created a daily schedule

            SPDailySchedule schedule = new SPDailySchedule(); // create a daily schedule to run the timer job
            schedule.BeginHour = 1;
            schedule.EndHour = 2;

            myJob.Schedule = schedule;
            myJob.Update(); // assign the schedule to the timer job
        }

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.