Get Recurring Jobs?

I am using recurring jobs to call into a WCF service to send emails.

I would like to create a UI for our users to be able to add/update recurring jobs as they please. (i.e. - change the time of day that their emails can be sent)

JobStorage.Current.GetMonitoringApi() seems to have all information about the background jobs which I’m not currently using at the moment.

Is it possible to get a list of RecurringJobs or a RecurringJob by ID?

I’m using the latest Hangfire 1.4

Thank you

Actually, I just found it:

StorageConnectionExtensions.GetRecurringJobs();

Sethiron, Hi :)!
You can save the recurring jobs ids on some place too. And when user need trigger or change the job, you can use RecurringJob.AddOrUpdate again. I Think this is better approach. That way, grants that if the job don’t exists for any reasons, he will create the job again.

1 Like

List<RecurringJobDto> recurringJobs = Hangfire.JobStorage.Current.GetConnection().GetRecurringJobs();

2 Likes

I cannot compile JobStorage.Current.GetConnection().GetRecurringJobs();
IStorageConnection got no definition for GetRecurringJobs() says VS.
What am I missing?

[EDIT] got it, namespace is Hangfire.Storage

Hi. I cannot compile `RecurringJobDto’. Is this something already exists in older patch or do I have to create a DTO of my own? If I have to created, what should I implement inside that DTO?

Hi. I can’t use either the first one or the second one you implement above. Is it because the newer version has changed the name? If so, can you update me with it?

Kaffein_persona, the DTO is in Hangfire.Storage under Hangfire.Storage.RecurringJobDto.

List<Hangfire.Storage.RecurringJobDto> recurringJobs = new List<Hangfire.Storage.RecurringJobDto>();

recurringJobs = Hangfire.JobStorage.Current.GetConnection().GetRecurringJobs().ToList();

There’s no GetRecurringJobs() after GetConnection(). Do you know why?

GetRecurringJobs() is an extension method. You need to add “using Hangfire.Storage” (the most common element missing in any C# documentation!).