Dynamically change the crontab of recurring jobs

Good morning everyone,

has anyone ever tried to edit the recurring jobs crontab?
I tried, unsuccessfully though.

In two words, I run Hangfire in a docker container, using a homemade Nuget that allows to read some startup parameters, including the recurring jobs crontab, via an API call to another docker container and put Hangfire listening on a Rabbit bus.

When a user changes parameters from the frontend, a message is issued on the bus for the specific container; all listening containers, if affected, invoke the API call again, updating the parameters.

However, even though the value of the crontab in memory is actually updated, already scheduled jobs do not acknowledge the change.
I think the reason is the use of Hangfire on SQL Server.
Is there any way to update job information on SQL Server and force Hangfire to re-read them, or delete and rewrite them, without restarting the container?

I searched the forum, finding some interesting insights, but nothing similar to my case.
Any suggestions?

Thanks!

I had to do something like this. I ended up making a page outside of the dashboard although I would guess with some extra effort it might be done with the dashboard extensions. (Maybe?)

Anyway, I made a new page that will list the recurring jobs and call “RecurringJob.AddOrUpdate” on the selected one updating the crontab.

We mainly use this to enable/disable a recurring job, but we have changed the crontab to a different schedule as well.

Not as easy as just changing the SQL table but it is effective.

1 Like