Add RecurringJob without Updating (RecurringJob.Add)

Hi,

I’ve been testing out Hangfire and it has been great so far. Thanks for the amazing product!

There’s only one issue I’ve been having. I want to dynamically queue recurring jobs, but it hasn’t been possible so far. This is more or less what I’m trying to do:

string periodicity = DeterminePeriodicityBasedOnJobData(dynamicJobData);

var jobHandler = new MyUserJobHandler();
RecurringJob.AddOrUpdate(() => jobHandler.RunJob(dynamicJobData), periodicity);

In this case, dynamicJobData will be different for every user and I want to queue a different job for them depending on dynamicJobData.

After trying this out, didn’t behave the way I expected because it inserted only one recurring job and after that it just updated that same job. Inspecting the source code I found out that this is because the recurringJobId (which is used to add or update) is generated from the type name and method name of the methodCall argument.

I think it would be nice to have a RecurringJob.Add method that always adds a new recurring job to the queue, or an overload to the RecurringJob.AddOrUpdate method that allows the user to manually specify the recurringJobId.

Thanks again for sharing this wonderful project!

God, I feel so silly. :frowning:

As I kept reading the source code, I found a public RecurringJob.AddOrUpdate method that accepts a recurringJobId. I don’t know how I didn’t see this before in Visual Studio.

Works like a charm!

Cheers.