Registering recurring jobs on startup

Hi all, i’ve a net 8 application that will be deployed in many server.

1)On startup i read list of recurring job settings and register them by:

RecurringJob.AddOrUpdate(
recJob.Name,
() => jobRunner.RunRecurringJobAsync(jobType),
recJob.CronExpression,
queue: “recurring”
);

Is there any issue if multiple server to this same things many time? I want avoid to have some kind of lock on this, is it ok?

  1. Another thing, which signature should i use? The implementation above is marked as deprecated.

  2. One last thing: if i have 20 servers, which one will trigger recurring jobs?

Thanks all.

  1. Just to be clear, you don’t have to register the same jobs more than once. Hangfire will remember. So once you read an item from that list and register it as a job, it should be removed from the list. Hangfire will not prevent you from registering the same kind of job twice, so you will have to control that on your own.
  2. We use BackgroundJob.Schedule()
  3. Any of them. If you want only one specific server to handle the recurring ones, decorate your recurring job classes with a queue attribute and then have your servers starting up with specific queues, for example “recurring” and “others”.