Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I've been looking for information on making sure hangfire ONLY runs on the master server of a load-balanced environment and am drawing a blank.
I am getting logs that come from the process hangfire calls, but they are only appearing on the public servers, (some appear on master, but public has different logs come through)
This is very worrying and I wanted to make sure Hangfire was setup so it would only execute on the master server as it is using EF to write to SQL and is updating cache.
I am modifying it so it only processes the commands in the Compose function of HangfireJobsComposer so they are only run on the master server.
In a load balanced environment you can explicitly set the publisher and subscriber roles, with the publisher role being your master as described here:
You can then conditionally add the hang fire setup if you are on the correct role
Yeah that's done, I would like to know the recommended method of forcing hangfire to only use the master server.
So now you would use something like this:
And only add the hang fire setup on the correct role
A hack I've done before is if you know the machine names, and they won't change then just set the timing to never.
private static string GetTiming(string timing)
return System.Environment.MachineName == "FLASH"
And then call it like:
RecurringJob.AddOrUpdate<IAwesomeService>($"😎 Do great thing", x =>
That's a nice solution, if I run my own server I would definitely do that, but it's on Azure (and machine names change on there a lot).
My solution was ito completely rebuild how it was all working, I rejigged hangfire not to run on public at all.
The public partials call the same endpoint, it checks to see if it is a master server.
If not, it hits an endpoint on master that runs the same code and returns the results (whilst updating the cache and using a cacherefresher to tell the public instances to update their cache.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted