Starting Recurring Jobs


#1

We have been using Hangfire for a while in a load balanced cluster of web servers. We back it with a SQL server and it has worked well for us. Typically we fire off jobs to execute immediately or in the future and Hangfire has handled it well. But now I’m looking at periodic jobs and I’m trying to figure out the best way to manage them.

I would like for when the server starts up to read a configuration file and start a periodic job if it isn’t already running. But how do I check to see if it is already running? I could remove the job and re-add it. But then since I have multiple web servers, each of them will do this, removing existing jobs and adding them. This doesn’t feel right but I’m not sure what the right solution is. How should recurring jobs be scheduled and ensured they are scheduled properly?

Thank you


#2

have you tried http://docs.hangfire.io/en/latest/background-methods/performing-recurrent-tasks.html
RecurringJob.AddOrUpdate(() => Console.Write("Example"), Cron.Daily);

unless there’s some sort of server-specific local job you’re thinking of, then you might need to set up different queues? Another method is RecurringJob.Trigger("some-id"); would that fit your use case?