1

is it possible to specify the server on which to run timer-job?

Write in code or when deployed. I want to run on one app server.

0

Have you tried the below code?

public StartWorkflow(string jobName, SPWebApplication webApplication) : base(jobName, webApplication, null, SPJobLockType.Job)
{
this.Title = “Start Workflow Timer Job”;
}

SPJobLockType.None – The timer job runs on every machine in the farm on which the parent service is provisioned, unless the job I associated with a specified server in which case it runs on only that server (and only if the parent service is provisioned on the server).

SPJobLockType.ContentDatabase – Locks the content database. A timer job runs one time for each content database associated with the Web application.

SPJobLockType.Job – Locks the timer job so that it runs only on one machine in the farm.

  • Yes, I use SPJobLockType.Job. But, timerJob run on Web 1 or Web2 servers. I want to run on one of app server (App1 or App2). – alexaf Sep 12 '18 at 4:21
0

In my experience, the job runs on the server from where you deployed the WSP.

You can force that by "hard-coding" the server you need the job to run on, by using the appropriate SPServerJobDefinition constructor, see https://stackoverflow.com/a/44249024.

0

Inherit the timer job from SPServerJobDefinition.

 class MyCustomTimerJob : SPServerJobDefinition
    {
        public MyCustomTimerJob()
            : base()
        {
        }
        public MyCustomTimerJob(string jobName, SPServer server)
            : base(jobName, server)
        {
            this.Title = jobName;
        }
        public override void Execute(SPJobState _jobState)
        {
            // to do
        }
    }

Then specify the server.

MyCustomTimerJob myJob = new MyCustomTimerJob("My Timer Job", SPFarm.Local.Servers["Server"]);

Here is a thread which would be helpful for you.

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.