Triggering a scheduled job from multiple hangfire servers

Viewed 88

we are triggering a scheduled job in a configured interval and it is getting fired. This is working in a single hangfire server environment.

In some of our environment, we will be having more than one servers. So, at this scenario, all the servers will trigger that job at that particular interval. Can we restrict this job to be triggered from only one server?

string cronExpressionCleanupJob = "0 0 0/{2} ? * *"; 
RecurringJob.AddOrUpdate<CleanUpJobTriggerJob>(nameof(CleanUpJobTriggerJob),
    job => job.ExecuteJob(null, null), cronExpressionCleanupJob, TimeZoneInfo.Local);
var hangFireJobId = BackgroundJob.Enqueue<CleanUpJobTriggerJob>(x => x.ExecuteJob(null, null));
1 Answers

According to the documentation, you should not worry as long as you specify the same identifier for your recurring job.

The call to AddOrUpdate method will create a new recurring job or update existing job with the same identifier.

Related