How can I poll to verify that the Hangfire server is up and working

Hi,

My system is dependent on Hangfire being up. How can I poll Hangfire to verify that the server is up and working?

Define ‘Poll’ …

You can use the API to get the number of servers currently active and compare that. But it might be a little tricky because the server-list is maintained through a heartbeat-like mechanism. So if servers go stale/offline it might take a few minutes to see that reflected in the server list you get through the API.

Getting the servers is fairly easy :

GlobalConfiguration.Configuration.UseMongoStorage(…); // Or similar
var serverList = JobStorage.Current.GetMonitoringApi().Servers();

This will give you a List() of ServerDTO that you can then either just do a Count() on or if you want more granular checking you can go through the list and check for instance the server names.

If you actually want to check if the jobs run then the quickest way I can think of is to schedule a recurring job on your hangfire that does something like update the last modified timestamp of a dummy file every X minutes and then you can just monitor that files last modified timestamp to see if the jobs go through.

Of course that gets a little more tricky if you have multiple servers picking jobs from the same queue.

It all depends a bit on what your requirements are.

1 Like

I think the only way to be sure jobs are actually running is to setup an external process that will submit jobs to the server and wait for an expected result (console app, webjob in Azure, another separate instance of Hangfire, etc).