4

I have written a custom timer job that should only run on one server in the farm. The constructor is as follows:

public class MyCustomTimerJob : SPJobDefinition {

public MyCustomTimerJob () : base() { }

public MyCustomTimerJob (SPWebApplication webApp)
: base("CustomJobName", webApp, null, SPJobLockType.Job)
{
    this.Title = "CustomJobName";
}

I schedule the job with the following code:

SPDailySchedule schedule = SPDailySchedule.FromString("daily at 6:00");

MyCustomTimerJob job = new MyCustomTimerJob(webApp);
job.Schedule = schedule;
job.Update(true);

When I look at the Scheduled Jobs in Central Admin, it shows the job scheduled to run on all 3 WFE servers. I expected it to only be scheduled on a single server since the lock type is SPJobLockType.Job.

When the scheduled time comes, the job does not run and I don't see anything in the ULS logs.

Of course this is a new production deployment and the issue cannot be reproduced in the test or dev farms.

Any suggestions?

2 Answers 2

2

As you can see here: http://manomangaldas.blogspot.be/2008/06/sharepoint-job-spjoblocktype-which-one.html

even if you see the job scheduled on all WFE, actually it will run on single server (one instance) when Lock Type is Job.

1

I know it's ages for this question to be asked. But I was working on a 2019 Farm and came across a similar issue. I have this legacy code, the Timer Job is activated via a Feature Event receiver. The old code was having job constructor with SPJobLockType.ContentDB which I changed to SPJobLockType.Job.

On updating the solution I was still getting multiple instances running. Which was very confusing.

On Feature Activated Code:

TimerJob job = new TimerJob("JOB_NAME", webApp);
job.Schedule = schedule;
job.Update();

Timer Job Constructor Code:

public TimerJob(string jobName, SPWebApplication webApplication)
           : base(jobName, webApplication, null, SPJobLockType.Job)
        {
            this.Title = "Some Timer Job Title";
        }

I updated the wsp package on the farm using Update-SPSolution PowerShell command.

Here we need to understand that the feature was not reactivated by the above command. And the way the code was written, Job needed to be reactivated so that new SPJobLockType is applied.

All I did was deactivated the feature and then Activated it. This solved the problem and only single instance of Job were running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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