1

I use Hangfire to read files from FTP server and I have multiple server instances to read from FTP. I need the recurring job only trigger on one instance to prevent the same job to read from same file.

var jobId = BackgroundJob.Enqueue<FtpImageJob>(j => j.ExecuteAsync(null, device.NumericId, device.DeviceId, device.VehicleId, device.TenantId));
                BackgroundJob.ContinueJobWith<FtpDeleteJob>(jobId, j => j.ExecuteAsync(null, numericId), JobContinuationOptions.OnAnyFinishedState);
yacc
  • 2,915
  • 4
  • 19
  • 33
  • I corrected a misspelling in your title, this was probably the reason you didn't get answers. Be careful when spelliing your title next time... regards – yacc May 03 '20 at 15:35

2 Answers2

0

You may either use paid Hangfire.Pro package with Mutex feature or decorate your job function with [DisableConcurrentExecution] attribute.

MikelThief
  • 185
  • 1
  • 13
0

If you are looking to restrict execution of job to only one of the many Hangfire servers, use a separate queue that only exists on one server. This way your recurring job will only execute on that hangfire server that's serving that queue.

Jawad
  • 11,028
  • 3
  • 24
  • 37