We have multiple web servers running our sites, with load balancers, so users are directed to different servers depending on the load. The code is the same for each instance on each server, and we have recurring jobs that are run. Obviously we dont want the jobs to run at the same time on both servers.
Does hangfire implement a lock when a job is run so it is not run again automatically?
Currently we have this already on each method that is run [Hangfire.DisableConcurrentExecution(60 * 60 * 5)] will that stop both servers running the code at the same time?
In order to get around this in the end, i did the following
These attributes are added to my interfaces
PingUrl is an attribute created to stop the IIS process from shutting down after 20 minutes on either server, nothing to do with this fix, just thought i would mention it
Queue is the recommended way now according to hangfire.
DisableConcurrentExecution is the attribute i thought i needed only, but you also need the one below.
SkipWhenPreviousJobIsRunning is a new attribute, that looks like this
Basically this checks to see if the job is already running and if so, cancels it. We now have no problems with jobs running on both servers at the same time.