(Resolved) Hangfire to only run jobs on specific server.
l
We have a website where the customer facing site (FE) and Umbraco (BE) run on different servers. We have Hangfire installed via Cultiv.Hangfire. Some jobs get scheduled from the FE and some from the BE. At the moment Hangfire seems to pick either server to run a job. My question, how can I tell Hangfire to only run jobs on one specific server, the BE one. Site is running 13.3.0 Also, great package @Sebastiaan
n
You can inject in the the Server Manager (I can't remember the actual interface you need sorry) but that would allow you to check if the current server is the publisher server. If it's the publisher continue running the job, else cancel execution.
l
If I were to cancel the job the execution, would it then eventually go on to run on the correct server? Do you happen to have any links to this?
n
I'm not sure if it would then eventually go on to run on the correct server I'm affraid.
This might actually help, it's more Hangfire specific than Umbraco specific, https://discuss.hangfire.io/t/make-sure-job-is-excuted-from-one-specific-server/4173
https://docs.umbraco.com/umbraco-cms/fundamentals/setup/server-setup/load-balancing/flexible-advanced << this talks about the IServerRoleAccessor interface which you mgiht want to use in conjunction with the custom hangfire bits
l
Thanks @Nik, ill check out the above
m
Sebs package has a setting for disabling it on a server
Looks like you just need Hangfire:Server:Disabled true set
s
That's right, drop it in your environment variables for all servers except the one that needs to run the jobs, that's exactly what this setitng was added for 👍 > Also, great package @Sebastiaan Thanks! 🙌
l
Thanks, thats been done, deploying out now
s
I also have a really bad hack:
Copy code
cs
    private static string GetTiming(string timing)
    {
        return Environment.MachineName == "FLASH" || Environment.MachineName == "KILLERQUEEN" || Environment.MachineName == "RADIOGAGA"  ? Cron.Never() : timing;
    }
so based on machine name I return
Cron.Never()
or use the timing specified in
RecurringJob.AddOrUpdate
- but it requires the machine name to be always predictable.
167 Views